Click here to Skip to main content
15,943,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am working on a billing system and for that purpose i have two tables

1- Bill [Bill_ID (PK Auto Incremental, Bigint), date, amount, ... etc]
2- BillDetails [Bill_ID (FK from bill), Item_ID, quantity, unitprice, ... etc]

When a new bill is created a record is inserted into [Bill] table and the last insrted id is used for [BillDetail] that we know a bill can have multiple items sold/purchased.

Now came to problem that occurs when a [Bill] record is inserted and an error occurred in [BillDetail] insertion DB got inconsistency.

So is there any way to get the new Bill_ID of [Bill] before committing its query.

Thank u for ur time and consideration.

1 solution


Please check the order of insertion.

Insert the record into the Bill Table and get the billid using @@IDENTITY.

Now insert the individual record into BillDetails.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900