本文介绍了如何在 SQL Server 2005 的一个语句中更新两个表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想一次更新两个表.我如何在 SQL Server 2005 中做到这一点?
I want to update two tables in one go. How do I do that in SQL Server 2005?
UPDATE
Table1,
Table2
SET
Table1.LastName='DR. XXXXXX',
Table2.WAprrs='start,stop'
FROM
Table1 T1,
Table2 T2
WHERE
T1.id = T2.id
AND
T1.id = '010008'
推荐答案
你不能在一个语句中更新多个表,但是你可以使用一个事务来确保两个 UPDATE
语句是原子处理.您还可以对它们进行批处理以避免往返.
You can't update multiple tables in one statement, however, you can use a transaction to make sure that two UPDATE
statements are treated atomically. You can also batch them to avoid a round trip.
BEGIN TRANSACTION;
UPDATE Table1
SET Table1.LastName = 'DR. XXXXXX'
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id
and T1.id = '011008';
UPDATE Table2
SET Table2.WAprrs = 'start,stop'
FROM Table1 T1, Table2 T2
WHERE T1.id = T2.id
and T1.id = '011008';
COMMIT;
这篇关于如何在 SQL Server 2005 的一个语句中更新两个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!