An update statement can only update one table at a time. Can you describe what you need to do or why you need to update multiple tables at once?
Perhaps what you require is multiple update statements wrapped in a single transaction so that you can be sure all of the updates occur together or none of them?
Any modification including UPDATE, INSERT or DELETE must reference column from one base table. So, you can't update multiple tables in one single query. However, you can use Transaction to execute them in one batch; also you can use output clause if you want to get the updated values.
Begin Transaction Update Query 1 Update Query 2 Commit TransactionHope this will help
As alternative you can write something like that
BEGIN TRANSACTION
BEGIN TRY
Update
Update
Update
COMMIT
END TRY
BEGIN CATCH
END CATCH;
Hi All, Is there any way to update multiple tables in a single query. I know we can write triggers. Apart from triggers, is there any other way available in SQL Server. I am using 2008R2.
A query is not a statement; queries do not change data and statements can. TRIGGERs are procedural code, so good SQL programmers hate them -- the way that Vegans hate eating babies (so wrong , so many ways).
In a well designed schema, we have one fact, one way, one time. This means that with DRI actions and REFERENCES constraints we will never have to do what you want to do! But you posted no DDL, no data and nothing to help us educate you.
Want to try again and be specific?