I have two tables, I need to update both table at same time.
Tables:
- BillMaster (ID, Date, CustomerName)
- BillDetail (BillDetailID, BillID, ItemName, Rate, Quantity, Amount)
ID
is the primary key and BillID
is a foreign key.
I have two tables, I need to update both table at same time.
Tables:
ID
is the primary key and BillID
is a foreign key.
to update both table at same time
It's not typically done that way; instead you update one table then the other in a transaction, and when the transaction completes both tables are changed, or if the transaction rolls back then both tables are unchanged. It thus looks like both updates have been done at the same time even though they are done by two update statements occurring one after the other
BEGIN TRANSACTION;
UPDATE BillMaster SET ... WHERE ID = @ID;
UPDATE BillDetail SET ... WHERE BillID = @ID;
COMMIT TRANSACTION;