数据库机房管理系统设计
数据库设计说明书
一、题目
姓名: 学号: 题目: 班级:
(42)机房管理系统
● 实现机房信息、机器信息、学生信息、上机类型信息的管理; ● 实现学生上机充值信息的管理;
● 实现学生上机过程的登记、费用信息的管理; ● 实现教学班及教学班学生信息的管理;
● 实现上机费率标准的设置及教学班上机的预约,即设置各教学班的上课
时段。
● 创建存储过程统计各机房上机费用的统计;
● 创建触发器实现费用登记时,自动修改该生的账户余额。 ● 建立各表之间的关系。
二、需求分析
针对一般高校机房管理系统的需求分析、通过对学生上机过程、教学班上机过程、注册过程、充值过程、的内容的数据流程分析一现设计如下数据项和数据结构 (1)机房基本信息:包括机房号、机房名、计算机数目、管理人等 (2)计算机基本信息:包括计算机IP 地址、编号、机房号、品牌、备注等 (3)学生基本信息:包括学号、姓名、性名、行政班等
(4)教学班基本信息:包括教学班班号、课程名称、课程性质、任课教师、教学班人数等 (5)用户基本信息:包括用户名、学号、密码、余额等
(6)学生充值基本信息:包括用户名、充值时间、金额、办理人等 (7)机房收费标准基本信息:包括机房号、时间段、金额等 (8)学生成绩基本信息:包括教学班号、学号、成绩等
(9)教学班机房预约基本信息:包括机房号、上课时段、开始时间、结束时间、教学班号
等
(10)学生上机过程登记基本信息:包括计算机IP 地址、日期、上机时间、下机时间、学
号、上机类型等
(11)机房费用统计基本信息:包括计算机IP 地址、日期、统计时间、费用等
(12)收费人员基本信息:包括收费员编号、收费员姓名、性别、身份证号码、时间段等
三、数据库概念结构设计
1、系统功能结构图
图1 系统功能结构图
2、局部E-R 图
机房学生
机房号机房号机房号机器数目学号姓名性别行政班
图2 机房实体E-R 图 图3 学生实体E-R 图
计算机
计算机ID编号机房号品牌备注
图4 计算机实体E-R 图
教学班
班级号课程性质课程名称任课教师班级人数
图5 教学班实体E-R 图
3、全局E-R 图
图6 实体和实体之间关系E-R 图
四、数据库逻辑结构设计
1、数据字典
2、关系图
五、数据库实现
1、创建数据库
1、创建数据库 create database room on
( name='room_data',
filename='E:\room\data\room_data', size=1MB, maxsize=3MB, filegrowth=1MB )
log on (
name='room_log',
filename='E:\room\log\room_log', size=1MB, maxsize=3MB, filegrowth=1MB )
2、room(机房表) 的创建 create table room (
rno int not null primary key, rname char(10) not null, number smallint null,
manager char(10) not null )
3、computer(计算机表) 的创建 create table computer (
IP char(20) not null primary key, cno smallint not null , rno int not null, brand char(20) null, note varchar(50) null )
2、创建表
4、student(学生表) 的创建 create table student (
sno int not null primary key, sname char(10) not null, sex char(2) null,
class char(20) not null )
5、class(教学班) 的创建 create table class (
clno int not null primary key, clname char(20) not null, cltype char(20) not null, teacher char(10) not null, clnumber smallint null )
6、User (用户表)的创建
create table usertable (
uname char(20) not null primary key, sno int not null,
pword char(20) not null, moneys money null, )
7、prepaid(充值表) 的创建
create table prepaid (
uname char(20) not null, ptime datetime not null,
pmoney smallmoney not null, trans char(10) not null,
constraint p_primary primary key(uname,ptime) )
8、standard(收费标准表) 的创建 create table standard (
rno int not null,
stime char(20) not null,
smoney smallmoney not null,
constraint c_primary primary key(rno,stime) )
9、result(成绩表)的创建
create table result (
clno int not null, sno int not null, result float null,
constraint r_prinary primary key(clno,sno) )
10、scheduled (教学班机房预定表)的创建 create table scheduled (
clno int not null, rno int not null,
stime char(20) not null,
begintime datetime not null, endtime datetime not null,
constraint s_primary primary key(rno,stime) )
11、record (上机过程登记表)的创建 create table record (
IP char(20) not null, sno int not null,
begintime datetime not null, endtime datetime null, type char(15) not null,
constraint t1 primary key(IP,begintime) )
12、statistik(费用统计表) 的创建 create table statistik (
IP char(20) not null,
dates datetime not null,
sno int not null,
moneys smallmoney not null,
constraint t2 primary key(IP,dates)
)
2、创建存储过程和触发器
1、 创建存储过程实现各机房上机费用的统计
1)代码
create proc s_room(@rno int)
as
select rname 机房名,sum(moneys) 费用
from statistik inner join computer
on computer.IP=statistik.IP inner join room on room.rno=computer.rno
where room.rno=@rno
group by rname
2)数据测试
exec s_room 514
2、创建触发器实现费用登记时,自动修改该生的账户余额。
1)代码
create trigger u_money on statistik
for insert
as
update usertable
set moneys=moneys-(select moneys from inserted)
where sno=(select sno from inserted)
2)数据测试
查询插入记录前学生的余额
select sno 学号,moneys 余额
from usertable
where sno=101
11
执行插入操作
insert into statistik
values('321-458-984',getdate(),101,3.5)
查询插入记录前学生的余额
select sno 学号,moneys 余额
from usertable
where sno=101
2、 创建触发器实现充值时自动修改该生余额
1)代码
create trigger un_money on prepaid
for insert
as
update usertable
set moneys=moneys+(select pmoney from inserted)
where uname=(select uname from inserted)
2)数据测试
select sno 学号,moneys 余额 from usertable
where sno=102
go
insert into prepaid
values('bbb',getdate(),4.8,'王俊')
go
select sno 学号,moneys 余额 from usertable
where sno=102
go
select * from
prepaid
12
六、结束语
通过这次课程设计,我更加熟练的掌握了数据库设计的方法,加深了对数据库课程知识的理解,同时也更加深入的了解了利用SQL 语言操纵数据库的知识,并且对数据库里面的存储过程有了比较深入的了解。经过几天的艰苦奋斗,我终于完成了我的数据库课程设计基于DB2的列车票务管理系统。进一步提高分析解决问题的综合能力。由于时间仓促,系统还有很多不足之处,所以开发的系统不是很完善,有一些功能未实现,但是列车票务管理的基本功能均已实现。以前对数据库的很多知识认识都不深刻,做过这次课程设计之后,我对数据库的知识有了一个比较系统的了解;比如:对表内一些字段的约束,关系等的运用已经比较熟练。由于是第一次使用,所以运用的不是很熟练。刚开始的时候,对于数据库设计方法等一系列知识都不熟悉,但当我基本完成此系统开发的时候,我发现其实也没有那么难,在未做之前我还害怕做不出来。经过对这个系统的开发,在开发过程中遇到但也解决了很多问题。这个课程设计使我巩固了数据库的知识。在今后的学习中我会加强理论与实践的结合,通过不断的摸索来弥补自己的不足之处。
13