Update a Specific Column in Entire Database

Essentially, in our entire database where ever there is a ModifiedDate column and if it is NULL we want to update that with current date time…

SELECT 'UPDATE ' + SCHEMA_NAME(t.schema_id) + '.' + t.name + ' SETModifiedDate = GETDATE() WHERE ModifiedDate IS NULL;'
FROM sys.tables AS t
WHERE c.name ='ModifiedDate'
ORDER BY SCHEMA_NAME(t.schema_id), t.name;

Above script will create an UPDATE script which will do the task.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s