Updating multiple tables in mssql

6854933580_2c8b688306_z

Here are the relevant clips from the MSDN documentation (emphasis is mine).

updating multiple tables in mssql-44updating multiple tables in mssql-26updating multiple tables in mssql-35updating multiple tables in mssql-12

you'd have to go UPDATE Table1 , Table2 SET Table1. XXXXXX' WHERE T1= T2DECLARE @ids TABLE (id int); BEGIN TRANSACTION UPDATE Table1 SET Table1. XXXXXX' OUTPUT INTO @ids WHERE T1.field = '010008'; UPDATE Table2 SET Table2.First table ("names") Well, there is an immediate advantage in performing just a single SQL query instead of two, and I believe it is quite clear: the server will have a lighter work load.At the same time, we will have a full control on the performed operation, which will be faster and easier to maintain.(Bug #11758262, Bug #50439) See Section 16.2.1.3, “Determination of Safe and Unsafe Statements in Binary Logging”, for more information.If you access a column from the table to be updated in an expression, assignments are generally evaluated from left to right.But they can be in a batch ( a set of SQL sent to the server in one round trip) keyword.

You must have an account to comment. Please register or login here!