使用内连接更新多个表 [英] Updating multiple tables with inner join

查看:36
本文介绍了使用内连接更新多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道您可以使用连接从多个表中选择多个列.是否可以使用连接更新多个表中的多个列?

I understand that you can select multiple columns from multiple tables by using joins. Is it possible to update multiple columns in multiple tables using joins?

推荐答案

不行.

您一次只能对一张表执行 UPDATEINSERT.

You can only do an UPDATE or INSERT into one table at a time.

如果你需要做多个,你可以将它们包含在一个事务中,以确保它们一起通过或一起失败:

If you need to do multiples, you can enclose them in a transaction to make sure they all pass or fail together, though:

BEGIN TRY
BEGIN TRAN

UPDATE Table1
SET Col1=Value1

UPDATE Table2
SET Col2=Value2

COMMIT TRAN
END TRY
BEGIN CATCH
IF @@TRANCOUNT>0 ROLLBACK
<error message reporting here>
END CATCH

这篇关于使用内连接更新多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆