How to update two tables in one query in MS SQL

Is it possible to update two tables that write a single query?

So, I do not need to fulfill two requests and track whether both of them are successful?

+4
source share
5 answers

You cannot do this in a request, but you can do it as a transaction when all requests in a transaction are either successful or unsuccessful.

+3
source

You can write a stored procedure that updates two tables and returns everything you need to determine success. Then this stored procedure can be called from one command. However, it should still contain two queries.

+1
source

No, this is impossible AFAIK.

EDIT: what is the reason for achieving this in a single query?

0
source

You can use transactions , but you still need to update the tables separately and check the results before executing or rolling back.

0
source

Of course you can use triggers

0
source

Source: https://habr.com/ru/post/1304233/


All Articles