How to Find All Primary Keys in the HEAT Help Desk Database.

Version 1

    Details

    Is there a SQL query to display all the Primary Keys in the HEAT database?


    Resolution

     

    Run the following in SQL Server Management Studio:

    SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,

     

    SCHEMA_NAME(schema_id) AS SchemaName,

     

    OBJECT_NAME(parent_object_id) AS TableName,

     

    type_desc AS ConstraintType

     

    FROM sys.objects

     

    WHERE type_desc IN ('PRIMARY_KEY_CONSTRAINT')

     

    ORDER BY TableName

     

    GO