Advertisement
Guest User

MS SQL: List Primary Key

a guest
Aug 5th, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.46 KB | None | 0 0
  1. SELECT ccu.COLUMN_NAME, ccu.CONSTRAINT_NAME
  2. FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS tc
  3.     INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE AS ccu
  4.         ON tc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME
  5. WHERE tc.TABLE_CATALOG = 'Your_Catalog'    -- replace with your catalog
  6.     AND tc.TABLE_SCHEMA = 'dbo'            -- replace with your schema
  7.     AND tc.TABLE_NAME = 'Your_Table'       -- replace with your table name
  8.     AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement