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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Nope.
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
回答2:
Not possible, unless you use triggers on the underlying table