I was required to update 40+ tables in our DB; Moran Benisty, our DBA master gave me a cool solution:
‘update ‘ + name + ‘ set SomeColumn = ”SomeValue” where OtherColumn = ”SomeOtherValueToMatchBy”’
name LIKE ‘LK_%’
Now all I had to do is copy the results and run them. Sweet !
BTW – use at your own risk. :)
2 thoughts on “Update multiple tables in SQL Server 2005”
I use it quite a bit, this is a great trick.
The bad side of it is when you do it for production, recursively.
Don’t forget sp_MSforeachtable
This helpful little guy "can" sometimes save the whole copy and paste bit:
e.g. EXEC sp_MSforeachtable ‘DBCC DBREINDEX (”?”)’
Comments are closed.