mysql 23000_MySQL:ERROR 1022(23000):无法写入;表’#sql-2b8...

我要实现一个书店数据库.我创建了表格书,作者和出版商.我想做出以下两种关系.

Book is written by Author.

Book is published by Publisher.

为了实现这些关系,我写了一些SQL语句,如:

create table book(

ISBN varchar(30) NOT NULL,

title varchar(30) not null,

author varchar(30) not null,

stock Int,

price Int,

category varchar(30),

PRIMARY KEY ( ISBN )

);

create table author(

author_id int not null auto_increment,

author_name varchar(15) NOT NULL,

address varchar(50) not null,

ISBN varchar(30) not null,

primary key (author_id)

);

alter table author add constraint ISBN foreign key (ISBN) references book (ISBN);

create table publisher(

publisher_id int not null auto_increment,

publisher_name varchar(15) NOT NULL,

address varchar(50) not null,

ISBN varchar(30) not null,

primary key (publisher_id)

);

alter table publisher add constraint ISBN foreign key (ISBN) references book (ISBN);

当MySQL shell执行最后一个alter语句时,我收到此错误.

ERROR 1022 (23000): Can't write; duplicate key in table '#sql-2b8_2'

原来,外键不能指定两次?怎么了?先感谢您.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值