Withdata Software

How to get primary key of a table from SQL Server

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE OBJECTPROPERTY(OBJECT_ID(CONSTRAINT_SCHEMA + '.' + CONSTRAINT_NAME), 'IsPrimaryKey') = 1
AND TABLE_NAME = 'my_table_name' AND TABLE_SCHEMA = 'my_schema_name'

See also:

How to get primary key of a table from PostgreSQL

How to get primary key of a table from SQLite

How to get primary key of a table from MySQL

How to get primary key of a table from DB2

How to get primary key of a table from Oracle

Some SQL Server tools you can try: https://www.withdata.com/sql-server/

Convert your data online, free

Free in-browser converters for CSV, Excel, JSON, XML and SQL: Withdata Online Data Conversion. Large files, batch conversion or scheduling? See the offline desktop apps, or browse all data conversion tools.