MySQL with foreign keys

Source: Internet
Author: User

Query for tables with foreign keys
Copy Code
Query specifies table foreign KEY constraints
Select
A.name as constraint name,
object_name (b.parent_object_id) as foreign key table,
D.name as foreign key column,
object_name (b.referenced_object_id) as main health watch,
C.name as primary key columns
From Sys.foreign_keys A
INNER JOIN Sys.foreign_key_columns B on a.object_id=b.constraint_object_id
INNER JOIN Sys.columns C on b.parent_object_id=c.object_id and b.parent_column_id=c.column_id
INNER JOIN Sys.columns D on b.referenced_object_id=d.object_id and b.referenced_column_id=d.column_id
where object_name (b.referenced_object_id) = ' table name to query ';

MySQL with foreign keys

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.