views:

241

answers:

5

Is it be possible to update two tables writing a single query?

So that i do not have to execute two queries and to track whether both are successful?

A: 

No, that is not possible AFAIK.

EDIT: What is the reason for you to achieve this in a single query?

shahkalpesh
+2  A: 

You can't do it in a query but you can do it as a transaction when all queries within the transaction will either succeed or fail.

lhahne
+1  A: 

You can write a stored procedure that updates the two tables and returns whatever you need it to in order to determine success. This stored proc can then be called from a single command. However, it will still have to contain two queries.

Robin Day
A: 

You could use transactions, however you are still required to update the tables separately and check the results before committing or rolling back.

hlovdal
+3  A: 

Ofcourse you can by using triggers

RJ1516