Created
March 16, 2018 13:04
-
-
Save richardbasile/aba3a540cf78f460a19389fc61394ebc to your computer and use it in GitHub Desktop.
SQL Server - Rename Default Constraints
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 'exec sp_rename N''dbo.[' + d.name + ']'', ''DF_' + upper(t.name) + '_' + lower(c.name) + ''';' cmd | |
from sys.tables t | |
join sys.columns AS c on c.object_id = t.object_id | |
JOIN sys.default_constraints AS d on d.parent_object_id = t.object_id and d.parent_column_id = c.column_id | |
where t.schema_id = 1 | |
and d.name <> 'DF_' + upper(t.name) + '_' + lower(c.name) | |
order by 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment