create database bookStore;
use bookStore;
create table book(
bookid int auto_increment not null,
catalogid int not null,
bookname varchar(20) not null,
price int not null,
picture varchar(30) not null,
primary key(bookid)
);
create table catalog(
catalogid int auto_increment not null,
catalogname varchar(20) not null,
primary key(catalogid)
);
create table orderitem(
orderitemid int auto_increment not null,
bookid int not null,
orderid int not null,
quantity int not null,
primary key(orderitemid)
);
create table orders(
orderid int auto_increment not null,
userid int not null,
orderdate timestamp not null,
primary key (orderid)
);
create table user(
userid int auto_increment not null,
username varchar(20) not null,
password varchar(20) not null,
sex varchar(4),
age int,
primary key(userid)
);
alter table book add constraint FK_Relationship_3 foreign key(catalogid)
references catalog(catalogid) on delete restrict on update restrict;
alter table orderitem add constraint FK_Relationship_2 foreign key (orderid)
references orders(orderid) on delete restrict on update restrict;
alter table orderitem add constraint FK_Relationship_4 foreign key (bookid)
references book(bookid) on delete restrict on update restrict;
alter table orders add constraint FK_Relationship_1 foreign key (userid)
references user(userid) on delete restrict on update restrict;