方法較多:
一、
EXEC sp_pkeys @table_name='tab'
二、
SELECT TABLE_NAME,
COLUMN_NAME
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE TABLE_NAME='tabl'
三、
SELECT A.NAME AS 表名,B.NAME AS 主鍵名
FROM SYSOBJECTS A
JOIN SYSOBJECTS B
ON A.ID=B.PARENT_OBJ
AND A.XTYPE='U' AND B.XTYPE='PK'
