-
-
Save disouzam/3310202db69cfd28ea580ff5c06020dc to your computer and use it in GitHub Desktop.
Add created_date column to all tables which don't have it already in SQL Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT 'ALTER TABLE ' + QUOTENAME(ss.name) + '.' + QUOTENAME(st.name) + ' ADD created_date DATETIME NULL;' | |
FROM sys.tables st | |
INNER JOIN sys.schemas ss on st.[schema_id] = ss.[schema_id] | |
WHERE st.is_ms_shipped = 0 | |
AND NOT EXISTS ( | |
SELECT 1 | |
FROM sys.columns sc | |
WHERE sc.[object_id] = st.[object_id] | |
AND sc.name = 'created_date' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment