MS SQL: List Primary Key
a guest Aug 5th, 2016 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- SELECT ccu.COLUMN_NAME, ccu.CONSTRAINT_NAME
- FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
- INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu
- ON tc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME
- WHERE tc.TABLE_CATALOG = 'Your_Catalog' -- replace with your catalog
- AND tc.TABLE_SCHEMA = 'dbo' -- replace with your schema
- AND tc.TABLE_NAME = 'Your_Table' -- replace with your table name
- AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY'
RAW Paste Data