Skip to content

Instantly share code, notes, and snippets.

@jbnv
Created July 8, 2015 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbnv/f2e3a553a21999566167 to your computer and use it in GitHub Desktop.
Save jbnv/f2e3a553a21999566167 to your computer and use it in GitHub Desktop.
Return the primary key for a particular table. (SQL Server)
SELECT column_name
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1
AND table_name = '<tableName>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment