Skip to content

Instantly share code, notes, and snippets.

@xivSolutions
Last active August 29, 2015 13:57
Show Gist options
  • Save xivSolutions/9583365 to your computer and use it in GitHub Desktop.
Save xivSolutions/9583365 to your computer and use it in GitHub Desktop.
SQL Server - Key Columns, with PK and IsIdentity Status
SELECT tc.TABLE_NAME, kcu.COLUMN_NAME, kcu.CONSTRAINT_NAME, tc.CONSTRAINT_TYPE,
(COLUMNPROPERTY(object_id(tc.TABLE_NAME), kcu.COLUMN_NAME, 'IsIdentity')) AS IsIDColumn
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
ON kcu.CONSTRAINT_SCHEMA = tc.CONSTRAINT_SCHEMA AND kcu.CONSTRAINT_NAME = tc.CONSTRAINT_NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment