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;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。