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:
2if not exists (select * from sys.columns
3 where object_id = object_id(''?'')
4 and name = ''CreatedOn'')
5begin
6 ALTER TABLE ? ADD CreatedOn datetime NOT NULL DEFAULT getdate();
7end';
Earning my money now cause I just shaved off a couple hours of billable time for my client.
Microsoft SQL Server