Sql updating multiple tables simultaneously
In general, the vast majority of queries only use inner joins and left joins, but it’s crucial to understand their relationship with cross joins as well to understand how you should ensure that the join produces at most one output row for each row to be modified.
In other words, a target row shouldn’t join to more than one row from the other table(s).
Beginning with SQL Server 2008, you can use MERGE command to perform these operations in a single statement.
The MERGE statement basically merges data from a source result set to a target table based on a condition that you specify and if the data from the source already exists in the target or not.
The new SQL command combines the sequence of conditional INSERT, UPDATE and DELETE commands in a single atomic statement, depending on the existence of a record.
Tr_Num SET = 1 where case when rest.class ='AC I' then res.book=1 when rest.class ='AC II' then res.book=1 when rest.class ='AC III' then res.book=1 end UPDATE res INNER JOIN rest ON = rest. PNR = 5; However, and maybe I misunderstand, but I suspect what you really want to do is actually an INSERT an UPDATE in a single transaction. Other DB sessions looking at the tables will always see the results of either none or all of the updates in the transaction (assuming you're not using the non-default transaction isolation level).
Tr_Num SET = 1, = 21 WHERE (rest.class ='AC I' OR rest.class ='AC II' OR rest.class ='AC III') AND rest.