--最近遇到MYSQL刪除外鍵報錯的問題
--問題來源:刪除一張數據表(名叫good_brands)報錯,(good_brands)表被(goods)表的外鍵限制,於是想到解除外鍵
--【1】顯示goods表的創建
show create table goods;
--【2】找到外鍵創建語句
CONSTRAINT `goods_ibfk_1` FOREIGN KEY (`brand_id`) REFERENCES `goods_brands` (`id`)
--【3】刪除外鍵
alter table drop foreign key goods_ibfk_1;
--注:第【3】句錯誤示范:
alter table drop foreign key brand_id; --brand_id不是外鍵!
【小結:刪除外鍵分三步】
【1】show create table 數據表名;
【2】找到CONSTRAINT `外鍵名` FOREIGN KEY (`xxxx`) REFERENCES `xxxxxx` (`id`)
【3】alter table drop foreign key 外鍵名;