Created
May 7, 2024 16:20
-
-
Save davepcallan/3a9f3a8e8460402606df8df172fb6ce7 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