开发者

Updating multiple tables with inner join

I understand that you can select multiple columns from multiple tables by using joins. Is it possible to update multiple columns in mu开发者_如何学Pythonltiple tables using joins?


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


Not possible, unless you use triggers on the underlying table

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜