Get a List of all Primary Keys in a Database

前端 未结 5 1959
囚心锁ツ
囚心锁ツ 2021-02-02 00:21

Is this the best way to - Get a List of all Primary Keys in a Database - or is there something better?

SELECT
KCU.TABLE_NAME AS Table_Name,
KCU.CONSTRAINT_NAME A         


        
5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-02 00:35

    look on link

    EXEC sp_pkeys ''
    EXEC sp_helpconstraint ''
    

    sp_pkeys will return a row for each column that participates in the primary key for . The columns you are likely most interested in are COLUMN_NAME and PK_NAME.

    sp_helpconstraint will list all constraints for , including foreign keys that reference the table. In the first recordset, there will only be a column called Object Name (kind of useless, since that's what you passed in). In the second resultset, there will be the following columns: constraint_type, constraint_name, and constraint_keys.

提交回复
热议问题