mysql查询某张表的外键

mysql和oracle一样也是有数据字典表的,是存在单独的一个库叫INFORMATION_SCHEMA,要查看某张表的外键要从字典表中查找

如mysql查询某张表的外键,可以用下面的方式查询

use INFORMATION_SCHEMA;

select TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME,REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME from KEY_COLUMN_USAGE where table_name = 'logistics_member_express';

+--------------------------+-----------------+----------------------------+------------------------+------------------------+

| TABLE_NAME               | COLUMN_NAME     | CONSTRAINT_NAME            | REFERENCED_TABLE_NAME  | REFERENCED_COLUMN_NAME |

+--------------------------+-----------------+----------------------------+------------------------+------------------------+

| logistics_member_express | id              | PRIMARY                    | NULL                   | NULL                   |

| logistics_member_express | express_user_id | Reflogistics_express_user6 | logistics_express_user | id                     |

+--------------------------+-----------------+----------------------------+------------------------+------------------------+

2 rows in set (0.00 sec)

如果某个外键不要的话就可以删除啦:

ALTER TABLE logistics_member_express DROP FOREIGN KEY  Reflogistics_express_user6;


你可能感兴趣的:(mysql查询某张表的外键)