SQL Server queries all foreign key child parent table relationships

Source: Internet
Author: User

SELECT Table_name,fk_name,reference_table_name,fk_list_number,fk_detail
From (
SELECT object_name (f.object_id) as Fk_name,
object_name (F.PARENT_OBJECT_ID) as TABLE_NAME,
object_name (f.referenced_object_id) as Reference_table_name,
k.constraint_column_id as Fk_list_number,
convert (sysname, col_name (k.referenced_object_id, k.referenced_column_id)) as Fk_detail
From Sys.foreign_keys F
INNER JOIN sys.foreign_key_columns k
On f.object_id = k.constraint_object_id and f.referenced_object_id = k.referenced_object_id
) T

SQL Server queries all foreign key child parent table relationships

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.