INSERT INTO two tables at one query

后端 未结 3 1927
你的背包
你的背包 2021-01-16 15:13

How can I insert values into two tables at once? if it not successful, both table should rollback.

I am using SQL server and the query passe throw C# code.

3条回答
  •  庸人自扰
    2021-01-16 15:52

    You could either run the two queries as one statement

    insert into table1 (...) values (...); insert into table2 (...) values (...)
    

    or write a trigger to do the second INSERT.

提交回复
热议问题