Query to find foreign keys

前端 未结 3 1728
梦毁少年i
梦毁少年i 2021-01-05 00:17

I have a database where I need to drop some foreign keys, but I don\'t know beforehand whether the foreign keys still exist.

I\'ve found some stored procedures (http

3条回答
  •  清酒与你
    2021-01-05 01:01

    You need to connect to the Information scheme and you can find all the information about the primary key and foreign keys in this table

     select
            concat(table_name, '.', column_name) as 'foreign key',  
            concat(referenced_table_name, '.', referenced_column_name) as 'references'
        from
            information_schema.key_column_usage
        where
            referenced_table_name is not null;
    

    HELP: see this link list-foreign-keys-in-mysql

提交回复
热议问题