INSERT INTO two tables at one query

后端 未结 3 1813
你的背包
你的背包 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.

    0 讨论(0)
  • 2021-01-16 16:01

    I would typically write a stored procedure to take in all of the values you want to write out, then call a series of INSERT INTO statements wrapped in a transaction.

    If you provide more information, such as table structure and sample data, we can help you further.

    0 讨论(0)
  • 2021-01-16 16:01

    get ans here of ur question

    SQL Server: Is it possible to insert into two tables at the same time?

    How can I INSERT data into two tables simultaneously in SQL Server?

    0 讨论(0)
提交回复
热议问题