如何查看表或列的所有外键?在MySQL中,如何获得指向特定表的所有外键约束的列表?某一列?这和这个甲骨文问题,但是对于MySQL。
3 回答
白板的微信
TA贡献1883条经验 获得超3个赞
表:
SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAMEFROM INFORMATION_SCHEMA.KEY_COLUMN_USAGEWHERE REFERENCED_TABLE_SCHEMA = '<database>' AND REFERENCED_TABLE_NAME = '<table>';
列:
SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAMEFROM INFORMATION_SCHEMA.KEY_COLUMN_USAGEWHERE REFERENCED_TABLE_SCHEMA = '<database>' AND REFERENCED_TABLE_NAME = '<table>' AND REFERENCED_COLUMN_NAME = '<column>';
动漫人物
TA贡献1815条经验 获得超10个赞
SHOW CREATE TABLE `<yourtable>`;
莫回无
TA贡献1865条经验 获得超7个赞
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';
添加回答
举报
0/150
提交
取消