SQL Server 2008: Find out primary/foreign key in Table?

后端 未结 5 888
再見小時候
再見小時候 2021-01-01 02:17

Does anyone know how I can see which are the primary & foreign keys in a table?

EDIT: Thanks for all the responses. I was looking for a SQL Query to do that. Rig

5条回答
  •  梦毁少年i
    2021-01-01 02:36

    You can start with:

    SELECT 
       Table_Name as [TableName], 
       Column_Name as [ColumnName],
       Constraint_Name as [Constraint], 
       Table_Schema as [Schema]
    FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
    ORDER BY 
       [TableName], 
       [ColumnName]
    

    (you can filter then by tableName)

提交回复
热议问题