资源描述
学院机房管理系统
数据库设计阐明书
设计人:
学号:
班级:
学院:
目录
一、需求分析
1.业务流程图
2.数据流图
3.数据字典
二、概念设计
1、实体属性图
2、全局E-R图
三、逻辑设计
1、表间关系图
2、关系模式
四、数据库实现
1、创立数据库
2、创立表
2、创立存储过程和触发器
一、需求分析
针对普通高校机房管理系统需求分析、通过对学生上机过程、教学班上机过程、注册过程、充值过程、内容数据流程分析一现设计如下数据项和数据构造
(1)机房基本信息:涉及机房号、机房名、计算机数目、管理人等
(2)计算机基本信息:涉及计算机IP地址、编号、机房号、品牌、备注等
(3)学生基本信息:涉及学号、姓名、性名、行政班等
(4)顾客基本信息:涉及顾客名、学号、密码、余额等
(5)学生充值基本信息:涉及顾客名、充值时间、金额、办理人等
(6)机房收费原则基本信息:涉及机房号、金额等
(7)学生上机过程登记基本信息:涉及计算机IP地址、日期、上机时间、下机时间、学号、上机类型等
(8)机房费用记录基本信息:涉及计算机IP地址、日期、记录时间、费用等
1.业务流程图
2.数据流图
3.数据字典
room(机房表)
字段名
数据类型
能否为空
与否为主键
阐明
rno
int
否
是
机房号
rname
char(10)
否
否
机房名
number
smallint
能
否
计算机数目
manager
char(10)
否
否
管理人
computer(计算机表)
字段名
数据类型
能否为空
与否为主键
阐明
IP
char(20)
否
是
计算机IP地址
cno
smallint
否
否
编号
rno
int
否
否
机房号
brand
Char(20)
能
否
品牌
note
Varchar(100)
能
否
备注
Student(学生表)
字段名
数据类型
能否为空
与否作为主键
阐明
sno
Int
否
是
学号
sname
Char(10)
否
否
姓名
sex
Char(2)
能
否
性别
class
Char(20)
能
否
行政班
Usertable(顾客表)
字段名
数据类型
能否为空
与否作为主键
阐明
uname
Char(20)
否
是
顾客名
sno
int
否
否
学号
pword
Char(20)
否
否
密码
money
money
能
否
余额
Prepaid(充值表)
字段名
数据类型
能否为空
与否作为主键
阐明
uname
Char(20)
否
是
顾客名
ptime
datetime
否
是
充值时间
pmoney
smallmoney
否
否
金额
trans
Char(10)
否
否
收费人员
Standard(收费原则表)
字段名
数据类型
能否为空
与否作为主键
阐明
rno
int
否
是
机房号
stime
Char(20)
否
是
时间段
smoney
smallmoney
否
否
金额/小时
Record(上机过程登记表)
字段名
数据类型
能否为空
与否作为主键
阐明
IP
char(20)
否
是
计算机IP地址
begintime
datetime
否
是
上机时间
sno
Int
否
否
学号
endtime
datetime
能
否
下机时间
type
Char(15)
否
否
上机类型
statistik (机房费用登记表)
字段名
数据类型
能否为空
与否作为主键
阐明
IP
char(20)
否
是
计算机IP地址
dates
datetime
否
是
日期
Sno
int
否
否
学号
moneys
smallmoney
否
否
费用
二、概念设计
1、实体属性图
机房
机器数目
机房号
机房名
管理人
学生
行政班
学号
姓名
性别
图一 机房实体E-R图 图二 学生实体E-R图
2、全局E-R图
机房
顾客
学生
计算机
机房号
机房名
机器数目
管理人
编号
机房号
品牌
备注
行政班
学号
性别
姓名
余额
密码
学号
顾客名
属于
上机
选取
属于
n
1
1
1
1
n
1
1
计算机ID
三、逻辑设计
1、表间关系图
2、关系模式
机房(机房号,机房名,机器数目,管理人)
学生(学号,姓名,性别,行政班)
计算机(编号,机房号,品牌,备注)
顾客(顾客名,学号,密码,余额)
四、数据库实现
1、创立数据库
1、创立数据库
create database room
on
( name='room_data',
filename='E:\room\data\room_data',
size=5MB,
maxsize=10MB,
filegrowth=1MB
)
log on
(
name='room_log',
filename='E:\room\log\room_log',
size=5MB,
maxsize=10MB,
filegrowth=1MB
)
2、创立表
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
)
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
)
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)
)
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、创立触发器实现费用登记时,自动修改该生账户余额。
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=508092
执行插入操作
insert into statistik
values('001',getdate(),101,2.5)
查询插入记录学生余额
select sno 学号,moneys 余额
from usertable
where sno=508092
3.创立触发器实现充值时自动修改该生余额
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=508092
go
insert into prepaid
values('bbb',getdate(),5,'个vga ')
go
select sno 学号,moneys 余额 from usertable
where sno=508092
go
select * from prepaid
展开阅读全文