0

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.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • [Why should I "tag my RDBMS"?](https://meta.stackoverflow.com/questions/388759/why-should-i-tag-my-rdbms) - please add a tag to specify whether you're using `mysql`, `postgresql`, `sql-server`, `oracle` or `db2` - or something else entirely. – marc_s May 16 '22 at 04:58
  • yes sorry im new..sql-server –  May 16 '22 at 05:03
  • @user19124549 Kindly give more details and also provide sample data and desired result for faster and better solution. – Nishant Gupta May 16 '22 at 05:12
  • Does this answer your question? [Stored procedure to update multiple tables](https://stackoverflow.com/questions/11444923/stored-procedure-to-update-multiple-tables) – MD. RAKIB HASAN May 16 '22 at 05:18
  • 1
    Please provide enough code so others can better understand or reproduce the problem. – Community May 16 '22 at 05:40
  • What does C# and .NET have to do with this? Please explain your situation, what code do you have so far? – Charlieface May 16 '22 at 08:38
  • Can you remove c# and .net tags from this question as they are not relevant? – shehanpathi Jun 12 '22 at 18:57

1 Answers1

3

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;
Caius Jard
  • 72,509
  • 5
  • 49
  • 80