mysql命令语法2

来源:互联网 发布:php编程教程 编辑:程序博客网 时间:2024/04/30 07:09
添加外键语法:alter table t_user add constraint u_paid_id2p_idforeign key (u_paid_id)references t_paid (p_id) on delete cascade on update cascade;注意key后面不要写表名,如果写成这样:alter table t_user add constraint u_paid_id2p_idforeign key t_user(u_paid_id)references t_paid (p_id) on delete cascade on update cascade;会报错:ERROR 1061 (42000): Duplicate key name 't_user'原因是mysql会把表名't_user'当成外键名称,然后再次新建外键时候会报重复外键的错,具体信息请参看mysql>show innodb status;找到LATEST FOREIGN KEY ERROR一行删除外键出错ERROR:Error on rename of "xxxx" to "xxx"(error:152)解决方法:正确删除索引后在删除key出错原因:使用了错误的外键名称,详见show innodb status命令

原创粉丝点击