一次查询将两个表插入 [英] INSERT INTO two tables at one query
本文介绍了一次查询将两个表插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将值一次插入两个表中?如果失败,则两个表都应回滚.
How can I insert values into two tables at once? if it not successful, both table should rollback.
我正在使用SQL Server,并且查询passe抛出C#代码.
I am using SQL server and the query passe throw C# code.
推荐答案
您可以将两个查询作为一条语句运行
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.
这篇关于一次查询将两个表插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文