Using MSSQL I needed to add a column to every table in a legacy database because I wanted to see whenever a new record was added. Needed a 'createdate' field that defaulted to getdate(), Instead of having to do each table one at a time I was able to find a query that did it all for me. Saved me a couple of hours. Thanks to Add a column if it doesn't exist to all tables?
Here is the code:
if not exists (select * from sys.columns
where object_id = object_id(''?'')
and name = ''CreatedOn'')
ALTER TABLE ? ADD CreatedOn datetime NOT NULL DEFAULT getdate();
EXEC sp_MSforeachtable '
Earning my money now cause I just shaved off a couple hours of billable time for my client.
Microsoft SQL Server