July 15, 2009 at 2:52 am
how to Perform update in multiple tables using single sql query
July 15, 2009 at 3:32 am
You can use dynamic sql to solve your problem, take all tables u want to update in a temp table and put your dynamic sql query in a loop changing value of table name(placed as a variable)
July 15, 2009 at 6:44 am
There is no way to update multiple tables from a single TSQL statement. If you want to update multiple tables, you will need multiple statements. I'm not sure that you'd need to create dynamic statements within a loop to accomplish this. You could simply write a series of update statements within a procedure.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
July 15, 2009 at 11:05 am
manikandan (7/15/2009)
how to Perform update in multiple tables using single sql query
There is one other approach you can use, and that's to use the system stored proc sp_MSforeachtable. It's a bit complex, but it works pretty well if you have a large number of tables that all need to be updated in the same fashion, like, for example, if you wanted to add an identity field to all the tables in your database since none had them.
There's a decent article on this stored proc
here.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply