我查看了我所要创建的外键和主键的类型,和编码的格式也没发现不对的地方,但是还是建表失败,这是图书代码
这是全部的SQL语句
管理员信息
CREATE TABLE Administrator(
name char(5) PRIMARY Key,
pwd char(8) not null,
CHECK(SEX IN('男','女')),
FamilyAddress varchar(100) not null,
birth datetime not null,
Age int(3)
);
'员工'
CREATE TABLE AdEmployee(
Ename char(10)PRIMARY Key,
Epwd char(8) not null,
CHECK(ESEX IN('男','女')),
EFamilyAddress char(20) not null,
Ebirth datetime not null,
EAge int(3)
);
'客房'
CREATE TABLE GuestRoom(
room int(4) not null,
CHECK (state IN('false','true')),
price decimal(9,2),
CHECK (roomkind IN('大','中','小')),
booktime datetime,
lefttime datetime,
PRIMARY Key(room,price)
);
'食物'
CREATE TABLE Food(
combo char(10) not null,
Fprice decimal(9,2) ,
PRIMARY Key(combo,Fprice)
);
'客人'
CREATE TABLE Guest(
Ename char(5) not null,
Gname char(10) not null,
CHECK(GSEX IN('男','女')),
Id char(20) not null,
room int(4),
Gday int(2) not null,
phone char(20) not null,
combo char(10),
FOREIGN Key(room) REFERENCES GuestRoom(room),
FOREIGN Key(Ename) REFERENCES AdEmployee(Ename),
FOREIGN Key(combo) REFERENCES Food(combo),
sum decimal(9,2),
PRIMARY Key(Gname,sum)
);
'结算'
CREATE TABLE Consumption(
Gname char(10) not null,
FOREIGN Key(Gname) REFERENCES Guest(Gname),
price decimal(9,2),
FOREIGN Key(price) REFERENCES GuestRoom(price),
Fprice decimal(9,2),
FOREIGN Key(Fprice) REFERENCES Food(Fprice),
other decimal(9,2),
sum decimal(9,2),
FOREIGN Key(sum) REFERENCES Guest(sum)
);