Updating 2 tables in sql

Posted by / 03-Jul-2020 16:15

Updating 2 tables in sql

Every now and then you will get someone asking how to update two tables with one statement in SQL Server. the person then walks away muttering something about how My SQL allows it. So I decided to try to see if I could update two tables with one statement. I"m working on an input form to track meter information.

You can additionally use MERGE statement to do the same as well, however I personally prefer this method.

In recent times I have seen a developer writing a cursor to update a table. We want to update the value from Table2 to Table1 for the rows where Col1 is 21 and 31.

When asked the reason was he had no idea how to use multiple tables with the help of the JOIN clause in the UPDATE statement. Additionally, we want to update the values of Col2 and Col3 only.

Order ID = 1002; UPDATE Books INNER JOIN Orders ON Books.

Using rollbacks, you can ensure that they are treated as one unit of work, ie either they are all executed or none of them are, to keep data consistent.

updating 2 tables in sql-44updating 2 tables in sql-87updating 2 tables in sql-28

How can I update multiple tables in My SQL with a single query?