数据库课程设计——火车票售票系统

数据库课程设计——火车票售票系统

听所有人很烦数据库课程设计?阅读本篇文章会让你不那么烦躁~

系统开发平台:

开发工具:eclipse,sublime
开发语言:Java,jsp,css,JavaScript
数据库:MySQL
中间件:tomcat 8.0
后台框架:SpringMVC
服务器:阿里云ECS
线上地址:http://www.shadowingszy.top/TrainTickets/login

系统功能:

用户层面:

添加用户。
修改用户个人信息。
修改用户状态。
删除用户。
根据用户名和密码获取用户的所有信息 。

订单层面:

添加订单。
修改订单信息。
删除订单。
根据用户ID获取订单信息。
锁定订单座位。

火车层面:

添加列车。
添加列车信息。
删除火车。
根据车站获取列车ID。
根据列车ID获取列车信息。
列车换乘查询。
查询列车座位剩余。
查询所有通列车的城市。
获取所有列车信息。

数据库设计:

carriage(车厢信息表):
carriage表
seats(车厢座位信息表):
在这里插入图片描述
money(火车里程-价位表):
在这里插入图片描述
order(订单表):
在这里插入图片描述
status(火车状态表):
在这里插入图片描述
stop(火车经停信息,即车站表):
在这里插入图片描述
train(火车表):
在这里插入图片描述
user(用户表):
在这里插入图片描述

难点SQL语句设计:

以下SQL语句均基于上述表结构进行的设计,数据库名为12307

锁定座位(锁定座位功能由两个SQL语句构成,这两个SQL语句构成一个事务):

select c1.cid, cd.location
from 12307.seat as s, 12307.carriage as c1
where c1.ctype = ? and s.next_to = ? and (c1.cid, s.location) not in (
select c2.cid,o.location
from 12307.order as o, 12307.carriage as c2
where o.tid = ? and c2.ctype = ? and o.date = ? and c2.cid = o.cid
and ((o.start_sid <= ? and o.end_sid <= ?) or (o.start_sid >= ? and o.end_sid >= ?))
)
select c1.cid, cd.location
from 12307.seat as s, 12307.carriage as c1
where c1.ctype = ? and (c1.cid, s.location) not in (
select c2.cid,o.location
from 12307.order as o, 12307.carriage as c2
where o.tid = ? and c2.ctype = ? and o.date = ? and c2.cid = o.cid
and ((o.start_sid <= ? and o.end_sid <= ?) or (o.start_sid >= ? and o.end_sid >= ?))
)

根据程序查询车次:

select a.tid, tname, a.sid as start_index, b.sid as end_index, a.station as start, b.station as end, a.arrive_time as start_time, b.arrive_time as end_time,b.mileage-a.mileage as mileage
from stop as a,stop as b,train as t
where a.city = ? and b.city = ? and a.sid < b.sid and a.tid = b.tid
and a.tid = t.tid and a.tid not in (
select tid
from status
where date = ? and status = ‘停运’
)

火车换乘:

select a.tid as firstTid, d.tid as secondTid, t1.tname as firstTname, t2.tname as secondTname, b.station as transfer_station
from 12307.stop as a, 12307.stop as b, 12307.stop as c, 12307.stop as d, 12307.train as t1, 12307.train as t2
where a.city = ? and d.city = ?
and a.tid = b.tid and b.station = c.station and c.tid = d.tid and b.tid <> c.tid
and a.sid < b.sid and c.sid < d.sid and b.arrive_time < c.arrive_time
and a.tid not in (select tid from status where date = ? and status = ‘停运’)
and d.tid not in (select tid from status where date = ? and status = ‘停运’)
and a.tid = t1.tid and d.tid = t2.tid

【重点来啦】本项目(包括源程序和表结构)的下载地址:

https://github.com/shadowings-zy/TrainTicketsSystem

其中名为“TrainTickets”的文件夹是项目源文件,名为“SQL”的文件夹内的文件是数据库的表结构,可直接导入MySQL workbench(也可以按照上面“数据库设计”内容中的表结构自行建表进行设计)。

猜你喜欢

转载自blog.csdn.net/u011748319/article/details/82808061