找出employee表的全部外鍵約束code
select TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA ='vhr' AND TABLE_NAME = 'employee';
Result:
blog
此時若是想刪除和posId相關的外鍵,只須要 alter table employee drop foreign key employee_ibfk_3;
table
找出以employee爲REFERENCED_TABLE的全部約束select
select TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE where CONSTRAINT_SCHEMA ='vhr' AND REFERENCED_TABLE_NAME = 'employee';
Result:
im