Skip to content

Instantly share code, notes, and snippets.

@richardbasile
Created March 16, 2018 13:04
Show Gist options
  • Save richardbasile/aba3a540cf78f460a19389fc61394ebc to your computer and use it in GitHub Desktop.
Save richardbasile/aba3a540cf78f460a19389fc61394ebc to your computer and use it in GitHub Desktop.
SQL Server - Rename Default Constraints
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