You can't update multiple tables in one statement

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'
 
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;

you can't update two tables at once, but you can link an update into an insert using OUTPUT INTO, and you can use this output as a join for the second update:
DECLARE @ids TABLE (id int);
BEGIN TRANSACTION

UPDATE Table1 
SET Table1.LastName = 'DR. XXXXXX'  
OUTPUT INSERTED.id INTO @ids
WHERE T1.field = '010008';

UPDATE Table2 
SET Table2.WAprrs = 'start,stop' 
FROM Table2 
JOIN @ids i on i.id = Table2.id;

COMMIT;
 The short answer to that is no. While you can enter multiple tables in the from clause of an update statement, you can only specify a single table after the update keyword. Even if you do write a "updatable" view (which is simply a view that follows certain restrictions), updates like this will fail. Here are the relevant clips from the MSDN documentation (emphasis is mine).
 

Comments

Popular posts from this blog

Create clean architecture with ASP.NET Core API

Threading with Mutex