Created
October 10, 2011 19:01
-
-
Save iancanderson/1276198 to your computer and use it in GitHub Desktop.
Get foreign key columns names of SQL SERVER tables
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
select pk.TABLE_NAME, c.COLUMN_NAME as 'foreign_key' | |
from INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk , | |
INFORMATION_SCHEMA.KEY_COLUMN_USAGE c | |
where | |
CONSTRAINT_TYPE = 'PRIMARY KEY' | |
and c.TABLE_NAME = pk.TABLE_NAME | |
and c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME | |
order by pk.TABLE_NAME |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment