How to determine the primary key for a table in SQL Server?

后端 未结 8 1987
小蘑菇
小蘑菇 2020-12-16 07:13

What I\'d like to be able to do in SQL Server 2005 somehow is with a table name as input determine all the fields that make up the primary key. sp_columns doesn

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 07:23

    select *
    from information_schema.Table_Constraints
    where Table_Name = @tableName
    

    See this MSDN Listing for Table Constraints.

提交回复
热议问题