Created
June 20, 2018 20:04
-
-
Save wlievens/3570a5e9674afcac8fd169c3f6699448 to your computer and use it in GitHub Desktop.
Automatically generated SQL for renaming single-column unique 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 | |
constraint_type, | |
tc.constraint_name, | |
tc.table_name, | |
kcu.column_name, | |
format('ALTER TABLE "%s" RENAME CONSTRAINT %s TO unq_%s_%s;', | |
tc.table_name, tc.constraint_name, tc.table_name, kcu.column_name) | |
FROM | |
information_schema.table_constraints AS tc | |
JOIN information_schema.key_column_usage AS kcu | |
ON tc.constraint_name = kcu.constraint_name | |
WHERE constraint_type = 'UNIQUE' | |
AND tc.constraint_name like 'uk\_%' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment