create table 航线
(航班号 char (10) primary key not null, 起点 char (10) not null, 目的地 char (10) not null, 票价 int not null,
foreign key (航班号) references 航班(航班号) )
在航线表中输入数据:
insert into 航线 values('0004','海南','北京','1200') insert into 航线 values('0006','北京','海南','1200') insert into 航线 values('0001','广州','上海','1000') insert into 航线 values('0002','南京','上海','500') insert into 航线 values('0005','北京','上海','800') insert into 航线 values('0007','海南','上海','1000') insert into 航线 values('0009','成都','广州','900') insert into 航线 values('0003','杭州','北京','600') insert into 航线 values('0008','上海','北京','700') insert into 航线 values('0010','海南','广州','600')
(4)机票表:(航班号,起飞时间,机舱等级,座位号,票价,折扣,预票状态,业务员)
create table 机票
(航班号 char (10) not null, 起飞时间 char (10) not null, 机舱等级 char (10) not null, 座位号 int not null,
票价 int not null, 折扣 char(10) not null,
11
预票状态 char(10) not null, 业务员 char(10 not null,) primary key (航班号,座位号), ); 3.2 数据载入
foreign key (航班号) references 航班(航班号)
图4-1 旅客表数据
图4-2 航班表数据
12
图4-3航线表数据
图4-4教材表数据
图4-5出版社表数据
4.运行
(1)各班学生用书表:班级、书号、书名、购买数量 select distinct Sclass,Book.Bno,Bname,BBamount from Student,BuyBook,Book where BuyBook.Sno=Student.Sno and BuyBook.Bno=Book.Bno
图5-1各班学生用书表
(2)售书登记表:学号、姓名、书号、购买数量
13
select Student.Sno,Sname,Bno,BBamount from Student,BuyBook
where BuyBook.Sno=Student.Sno
图5-2售书登记表
(3)缺书登记表:学号、姓名、书号、缺书数量
select Student.Sno,Student.Sname,BuyBook.Bno,BBamount-SRamount amount from Student,BuyBook,StackRoom,Book where BuyBook.Sno=Student.Sno and BuyBook.Bno=StackRoom.Bno and Book.Bno=BuyBook.Bno and
BuyBook.BBamount>StackRoom.SRamount
图5-2缺书登记表
教材存量表:书号、单价、库存量 select Book.Bno,Bprice,SRamount from Book,StackRoom,BuyBook where Book.Bno=StackRoom.Bno and Book.Bno=BuyBook.Bno
14
(4)
图5-4教材存量表
(5)待购教材表:书号、缺书数量
select BuyBook.Bno,BBamount-SRamount amount from BuyBook,StackRoom
where BuyBook.Bno=StackRoom.Bno and BuyBook.BBamount >StackRoom.SRamount
图5-5待购教材表
15