-
-
Save NaserKhoshfetrat/6ccc859619db193dc81cca246bc3988e to your computer and use it in GitHub Desktop.
misnamed sql server foreign key query
This file contains hidden or 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
-- https://gist.github.com/timabell/d017038af96196b84e56 | |
SELECT | |
obj.name, | |
fk.name | |
FROM sys.foreign_keys fk | |
inner join sys.objects obj on obj.object_id = fk.parent_object_id | |
-- use this where clause to find FKs that aren't named after their table: | |
where fk.name not like 'FK_' + obj.name + '_%' | |
order by | |
obj.name, | |
fk.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment