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

后端 未结 13 982
忘了有多久
忘了有多久 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:42

    If you use InnoDB and defined FK's you could query the information_schema database e.g.:

    SELECT * FROM information_schema.TABLE_CONSTRAINTS 
    WHERE information_schema.TABLE_CONSTRAINTS.CONSTRAINT_TYPE = 'FOREIGN KEY' 
    AND information_schema.TABLE_CONSTRAINTS.TABLE_SCHEMA = 'myschema'
    AND information_schema.TABLE_CONSTRAINTS.TABLE_NAME = 'mytable';
    

提交回复
热议问题