Skip to content

Latest commit

 

History

History
68 lines (51 loc) · 3.32 KB

view-foreign-key-properties.md

File metadata and controls

68 lines (51 loc) · 3.32 KB
title description author ms.author ms.reviewer ms.date ms.service ms.subservice ms.topic helpviewer_keywords monikerRange
View Foreign Key Properties
View the foreign key attributes of a relationship with SQL Server Management Studio or T-SQL queries.
WilliamDAssafMSFT
wiassaf
randolphwest
03/19/2024
sql
table-view-index
how-to
foreign keys [SQL Server], attributes
displaying foreign keys attributes
viewing foreign keys attributes
>=aps-pdw-2016 || =azuresqldb-current || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current||=fabric

View foreign key properties

[!INCLUDE sqlserver2016-asdb-asdbmi-asa-pdw-fabricsqldb]

You can view the foreign key attributes of a relationship in [!INCLUDE ssnoversion] by using [!INCLUDE ssManStudioFull] or [!INCLUDE tsql].

Permissions

[!INCLUDE ssCatViewPerm] For more information, see Metadata Visibility Configuration.

Use SQL Server Management Studio

  1. Open the Table Designer for the table containing the foreign key you want to view, right-click in the Table Designer, and choose Relationships from the shortcut menu.

  2. In the Foreign Key Relationships dialog box, select the relationship with properties you want to view.

If the foreign key columns are related to a primary key, the primary key columns are identified in Table Designer by a primary key symbol in the row selector.

Use Transact-SQL

  1. In Object Explorer, connect to an instance of [!INCLUDE ssDE].

  2. On the Standard bar, select New Query.

  3. Copy and paste the following example into the query window and select Execute. The example returns all foreign keys and their properties for the table HumanResources.Employee in the sample database.

    USE AdventureWorks2022;
    GO
    
    SELECT f.name AS foreign_key_name,
        OBJECT_NAME(f.parent_object_id) AS table_name,
        COL_NAME(fc.parent_object_id, fc.parent_column_id) AS constraint_column_name,
        OBJECT_NAME(f.referenced_object_id) AS referenced_object,
        COL_NAME(fc.referenced_object_id, fc.referenced_column_id) AS referenced_column_name,
        f.is_disabled,
        f.is_not_trusted,
        f.delete_referential_action_desc,
        f.update_referential_action_desc
    FROM sys.foreign_keys AS f
    INNER JOIN sys.foreign_key_columns AS fc
        ON f.object_id = fc.constraint_object_id
    WHERE f.parent_object_id = OBJECT_ID('HumanResources.Employee');

For more information, see sys.foreign_keys and sys.foreign_key_columns.

Related content