无法建立外键,请大哥们指点
时间:2011-12-28
来源:互联网
SQL code
上面三个外键,只能建立第一个,第二个的时候就报错:
[SQL] alter table carquote add constraint FK_HAS_MANY foreign key (pdbusbnid)
references business (bnid) on delete restrict on update restrict;
受影响的行: 0
时间: 0.110ms
[SQL]
alter table message add constraint FK_HAS_MANY foreign key (msgbusbnid)
references business (bnid) on delete restrict on update restrict;
[Err] 1005 - Can't create table 'test.#sql-6d4_17' (errno: 121)
外键名称不一样,但还是无法创建,为何啊,跪求指点,谢谢了。
/*==============================================================*/ /* DBMS name: MySQL 5.0 */ /* Created on: 2011/12/28 11:43:47 */ /*==============================================================*/ drop table if exists business; drop table if exists carquote; drop table if exists message; drop table if exists news; /*==============================================================*/ /* Table: business */ /*==============================================================*/ create table business ( bnid int not null, bnname varchar(20), bntype int, bncaraid int, bncarbid int, bnjt varchar(20), bnsellphone varchar(20), bncollphone varchar(20), website varchar(30), bnfax varchar(10), bnmap varchar(20), bnabout text, you int, bnmail varchar(20), bnwebsite varchar(30), bnaddress varchar(30), addressmore varchar(30), topimg varchar(80), seo varchar(256), primary key (bnid) ); alter table business comment '商家信息表,存储商家名称和电话等详细信息。'; /*==============================================================*/ /* Table: carquote */ /*==============================================================*/ create table carquote ( pdid int not null, pdbusbnid int not null, bnid int, pdtitle varchar(30), caraid int, carbid int, carcid int, pdimg varchar(70), pdpricea float, pdpriceb float, pdinfo varchar(256), pdstatus varchar(2), readnum int, primary key (pdid) ); alter table carquote comment '商家发布的产品信息'; /*==============================================================*/ /* Table: message */ /*==============================================================*/ create table message ( msgid int not null, msgbusbnid int not null, bnid int, msgtime int, msgtext varchar(256), reply varchar(256), rptime int, msgsuatus varchar(2), primary key (msgid) ); /*==============================================================*/ /* Table: news */ /*==============================================================*/ create table news ( newsid int not null, nbusbnid int not null, bnid int, newstitle varchar(20), newstag varchar(20), newstype int, ncontent text, newstime int, readnum int, primary key (newsid) ); alter table carquote add constraint FK_HAS_MANY foreign key (pdbusbnid) references business (bnid) on delete restrict on update restrict; alter table message add constraint FK_HAS_MANY foreign key (msgbusbnid) references business (bnid) on delete restrict on update restrict; alter table news add constraint FK_HAS_MANY foreign key (nbusbnid) references business (bnid) on delete restrict on update restrict;
上面三个外键,只能建立第一个,第二个的时候就报错:
[SQL] alter table carquote add constraint FK_HAS_MANY foreign key (pdbusbnid)
references business (bnid) on delete restrict on update restrict;
受影响的行: 0
时间: 0.110ms
[SQL]
alter table message add constraint FK_HAS_MANY foreign key (msgbusbnid)
references business (bnid) on delete restrict on update restrict;
[Err] 1005 - Can't create table 'test.#sql-6d4_17' (errno: 121)
外键名称不一样,但还是无法创建,为何啊,跪求指点,谢谢了。
作者: q309056448 发布时间: 2011-12-28
改个外间名字就可以创建了
mysql> alter table message add constraint FK_HAS_MANY1 foreign key (msgbusbnid) references business (bnid) on delete restrict on update restrict;
Query OK, 0 rows affected (0.15 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table message add constraint FK_HAS_MANY1 foreign key (msgbusbnid) references business (bnid) on delete restrict on update restrict;
Query OK, 0 rows affected (0.15 sec)
Records: 0 Duplicates: 0 Warnings: 0
作者: rucypli 发布时间: 2011-12-28
alter table carquote add constraint FK_HAS_MANY foreign key (pdbusbnid)
references business (bnid) on delete restrict on update restrict;
alter table message add constraint FK_HAS_MANY foreign key (msgbusbnid)
references business (bnid) on delete restrict on update restrict;
alter table news add constraint FK_HAS_MANY foreign key (nbusbnid)
references business (bnid) on delete restrict on update restrict;
名字重复了。
references business (bnid) on delete restrict on update restrict;
alter table message add constraint FK_HAS_MANY foreign key (msgbusbnid)
references business (bnid) on delete restrict on update restrict;
alter table news add constraint FK_HAS_MANY foreign key (nbusbnid)
references business (bnid) on delete restrict on update restrict;
名字重复了。
作者: ACMAIN_CHM 发布时间: 2011-12-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28