|
How can I update a column value in all tables in SQL Server |
|
|
|
|
Wednesday, 31 December 2008 |
|
This query will write out a SQL Query, which will Update a Column Value in All Tables
First, open SQL Server and select SQL Server Query Analyzer from the Tools menu. Type the following SQL statement in the query analyzer window (Type='U' specifies user-defined tables):
SELECT 'UPDATE ',RTRIM(Name),' SET UserID=2 WHERE UserID=1' FROM sysobjects
WHERE Type='U'
Run the SQL statement. Then copy the results from the result window, paste them in the query window, and run them.
Thanks to Venkat Alladi (devx.com) for this great timesaver - http://www.devx.com/tips/Tip/14129
|