我有两个表'member'和'book'定义为:
create table member(
mem_id bigint(11) unsigned auto_increment not null primary key,
firstname varchar(20) not null,
lastname varchar(20) not null,
gender varchar(1) not null
);
create table book(
book_id varchar(15) not null primary key,
isbn varchar(15) not null,
book_name varchar(100) not null
);
现在我想创建一个名为'return_book'的follwing表:
create table return_book(
mem_id bigint(11) unsigned not null,
book_id varchar(15) ,
date date,
primary key(mem_id, book_id),
foreign key(mem_id) references member(mem_id)
ON DELETE CASCADE,
foreign key(book_id) references book(book_id)
ON DELETE NO ACTION
ON UPDATE CASCADE
);
但是我总是得到以下错误:“无法创建表return_book” 请帮忙。
答案 0 :(得分:0)
您有语法错误
create table return_book(
mem_id bigint(11) unsigned not null,
book_id varchar(15) ,
date date,
primary key(mem_id, book_id),
foreign key(mem_id) references member(mem_id)
ON DELETE CASCADE,
foreign key(book_id) references book(book_id)
ON DELETE NO ACTION
ON UPDATE CASCADE
);
答案 1 :(得分:0)
'member'表中的列名'mem_id'中有一个拼写错误:D!此外,我还了解到引用的列和引用列必须具有相同的类型。