建表:将app_id设置为外键。
create table test4(id int not null primary key,app_id int not null, foreign key(app_id) references test3(id));
现删除外键,因sql语法为:alter table 表名 drop foreign key(外键字段名);
遂将sql写成了
alter table test4 drop foreign key app_id;
执行结果如下:
原因分析:app_id不是外键的字段名。
查外键名的方法:show create table 表名;
上图中CONSTRINT后面的值就是外键字段名。
最后执行撤销外键sql:
alter table oliver_test4 drop foreign key test4_ibfk_1;