daily pastebin goal
46%
SHARE
TWEET

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!
  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'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top