Skip to content

Instantly share code, notes, and snippets.

@gabrielribeiro
Created February 3, 2015 19:31
Show Gist options
  • Save gabrielribeiro/5370c737f3e52b39c472 to your computer and use it in GitHub Desktop.
Save gabrielribeiro/5370c737f3e52b39c472 to your computer and use it in GitHub Desktop.
SELECT
'sp_rename ''' + OBJECT_NAME(OBJECT_ID) + ''', ''PK_' + OBJECT_NAME(parent_object_id) + '''' AS [PROC],
OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc LIKE 'PRIMARY_KEY_CONSTRAINT' AND OBJECT_NAME(parent_object_id) <> 'sysdiagrams'
AND OBJECT_NAME(OBJECT_ID) <> 'PK_' + OBJECT_NAME(parent_object_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment