在SQL Server的单个查询中将数据插入到两个表中 [英] insert data into two tables in a single query in sql server
本文介绍了在SQL Server的单个查询中将数据插入到两个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
在SQL Server的单个查询中将数据插入到两个表中
感谢
Hi all,
insert data into two tables in a single query in sql server
thanks
推荐答案
您无法通过单个查询来完成此操作.
尝试改用存储过程.
You cannot do this through a single query.
Try using a stored procedure instead.
您不能通过单个查询在两个表中插入记录,而是可以在第一个插入时写一个 trigger 表格插入第二张表格.
希望对您有帮助:)
You can''t insert records in two tables through a single query, instead you can write a trigger on insert of first table to insert in second table.
hope it helps :)
Abhinav是正确的,您可能确实需要一个存储过程-替代方法是使用 ^ ],在该表中,直到事务完成为止,数据都不会完全输入到任何一个表中;如果出现问题,则可以回滚.这将使您的数据库完整性正常.
Abhinav is correct, you probably do need a stored procedure - the alternative is to use a Transaction[^], where the data is not entered fully in either table until the transaction is complete, and can be rolled back if there is a problem. This would leave your database integrity ok.
这篇关于在SQL Server的单个查询中将数据插入到两个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文