How do I see all foreign keys to a table or column?

后端 未结 13 1002
忘了有多久
忘了有多久 2020-11-22 09:14

In MySQL, how do I get a list of all foreign key constraints pointing to a particular table? a particular column? This is the same thing as this Oracle question, but for MyS

13条回答
  •  天涯浪人
    2020-11-22 09:38

    As an alternative to Node’s answer, if you use InnoDB and defined FK’s you could query the information_schema database e.g.:

    SELECT CONSTRAINT_NAME, TABLE_NAME, REFERENCED_TABLE_NAME
    FROM information_schema.REFERENTIAL_CONSTRAINTS
    WHERE CONSTRAINT_SCHEMA = ''
    AND TABLE_NAME = ''
    

    for foreign keys from

    , or

    SELECT CONSTRAINT_NAME, TABLE_NAME, REFERENCED_TABLE_NAME
    FROM information_schema.REFERENTIAL_CONSTRAINTS
    WHERE CONSTRAINT_SCHEMA = ''
    AND REFERENCED_TABLE_NAME = '
    '

    for foreign keys to

    You can also get the UPDATE_RULE and DELETE_RULE if you want them.

    提交回复
    热议问题