资源描述
数据库原理及应用
——图书馆管理系统数据库设计
一. 需求分析
需求分析的任务是调查应用领域,对应用领域中各应用的信息要求和操作要求进行详细分析,形成需求分析说明书。重点是调查,收集与分析用户在数据管理中的信息要求、处理要求、数据的安全性与完整性要求。
功能模块设计
将图书管理系统业务分为四个大的方面:学生数据管理、图书征订管理、藏书管理、
图书流通管理。
功能模块图
功能模块分析
办卡、挂失、注销
学生在图书馆中必须持卡办理一切业务,新生必须首先办理借书卡,当借书卡丢失时需办理挂失业务,毕业生或中途退学者必须办理注销卡业务,以防止借书卡的流失。
查询、借书、环书、注销
学生在图书馆中持卡可以进行以下业务:查询自己借书状态,借书,还书,当所借书籍丢失时需办理注销业务。
图书查询、缺书登记
学生需要查询自己所需书籍时,若馆中有则直接借书;若馆中没有,可以进行缺书登记。
数据流程分析与设计
数据流程图
数据字典的建立
数据字典
数据字典是我在数据流程图中选取的一些中层数据流,我把我所抽去的数据列出以下表来。数据项
数据项名
数据类型
长度
别名
取值范围
Sno
字符型
10
学号
Sname
字符型
10
姓名
Ssex
字符型
2
性别
男、女
Sgrade
字符型
10
年级
Sdept
字符型
10
学院
Smajor
字符型
10
专业
Sclass
字符型
10
班级
Bno
字符型
10
条码号
Bname
字符型
10
书名
Bahthor
字符型
10
作者
Bpress
字符型
10
出版社
Bprice
浮点型(单精度)
10
定价
Pno
字符型
10
馆藏地编号
1—10
Bstate
字符型
10
图书状态
Bbstate
字符型
10
借阅状态
Cno
字符型
10
卡号
Bno
字符型
10
条码号
Bbno
字符型
10
借书代号
Bbtime
日期型
10
借书时间
(应还时间—借书时间)小于一个月
Brtime
日期型
10
应还时间
Pno
字符型
10
馆藏地编号
1—10
Pname
字符型
10
馆藏地名称
Cno
字符型
10
卡号
Rtime
日期型
10
时间
Rstate
字符型
10
欠书状态
Rfine
浮点型(单精度)
10
超时罚款
Cno
字符型
10
卡号
Cstate
字符型
10
卡状态
Sno
字符型
10
学号
Qname
字符型
10
书名
Qahthor
字符型
10
作者
Qpress
字符型
10
出版社
Qprice
浮点型(单精度)
4
定价
Qfrequence
整型
4
搜索频率
数据机构
数据结构名
含义说明
组成
学生信息
记录学生的基本信息
学号、姓名、性别、年级、学院、专业、班级
图书信息
记录图书的基本信息
条码号、书名、作者、出版社、定价、馆藏地编号、图书状态、借阅状态
借阅信息
记录学生借书信息
卡号、条码号、借书代号、借书时间、应还时间
馆藏地信息
图书的分布情况
馆藏地编号、馆藏地名称
学生日常事务信息
反映学生借书状态,如是否允许借书等
卡号、时间、欠书状态、超时罚款
借书卡信息
学生借书卡基本信息,放映学生借书卡状态
卡号、卡状态、学号
缺书登记
记录学生需要图书(馆内没有)信息
书名、作者、出版社、搜索频率、定价
二. 概念结构设计
E-R图
根据前面的需求分析,可以将图书管理系统数据库实体划分为图书信息实体集、学生信息实体集、馆藏地实体集、借书卡信息实体集、缺书信息实体集,各实体集里还包含不同的实体以下包括所有的实体。
学生:{学号,姓名,性别,年级,学院,专业,班级}
图书:{条码号,书名,作者,出版社,定价,馆藏地编号,图书状态,借阅状态}
馆藏地:{馆藏地编号,馆藏地名称}
借书卡:{卡号,卡状态,学号}
缺书:{书名,作者,出版社,定价,搜索频率}
学生日常事务信息:{卡号,时间,欠书状态,超时罚款}
E-R图
三. 逻辑结构设计
概念模型向关系模型的转变将E-R图转换为关系模型,即将实体、实体的属性和实体之间的联系转化为关系模式,为应用程序建立专门的视图而不必要应用程序直接访问数据表
关系模式的设计
Student
数据项名
数据类型
长度
别名
是否为空
主外键
Sno
字符型
10
学号
否
主键
Sname
字符型
10
姓名
Ssex
字符型
2
性别
Sgrade
字符型
10
年级
Sdept
字符型
10
学院
Smajor
字符型
10
专业
Sclass
字符型
10
班级
Book
数据项名
数据类型
长度
别名
是否为空
主外键
Bno
字符型
10
条码号
否
主键
Bname
字符型
10
书名
否
Bahthor
字符型
10
作者
否
Bpress
字符型
10
出版社
否
Bprice
浮点型(单精度)
4
定价
否
Pno
字符型
10
馆藏地编号
否
外键
Bstate
字符型
10
图书状态
否
Bbstate
字符型
10
借阅状态
否
Jieyue
数据项名
数据类型
长度
别名
是否为空
主外键
Cno
字符型
10
卡号
否
外键
主键
Bno
字符型
10
条码号
否
外键
Bbno
字符型
10
借书代号
否
Bbtime
日期型
10
借书时间
否
Brtime
日期型
10
应还时间
否
Btime
日期型
10
还书时间
(应还时间—借书时间)等于一个月
Place
数据项名
数据类型
长度
别名
是否为空
主外键
Pno
字符型
10
馆藏地编号
否
主键
Pname
字符型
10
馆藏地名称
否
Rountin
数据项名
数据类型
长度
别名
是否为空
主外键
Cno
字符型
10
卡号
否
外键
主键
Rtime
日期型
10
时间
否
Rstate
字符型
10
欠书状态
否
Rfine
浮点型(单精度)
10
超时罚款
否
对时间的检查,当借还书中的还书时间小于应还时间时,超时罚款为零;当超过应还时间未还书时,开始计费,超时罚款=(时间-应还时间)*0.01;当借还书中的还书时间确定时,超时罚款=(还书时间-应还时间)*0.01。
Card
数据项名
数据类型
长度
别名
是否为空
主外键
Cno
字符型
10
卡号
否
主键
Cstate
字符型
10
卡状态
否
Sno
字符型
10
学号
否
外键
LinkBook
数据项名
数据类型
长度
别名
是否为空
主外键
Qname
字符型
10
书名
否
主键
Qahthor
字符型
10
作者
否
Qpress
字符型
10
出版社
否
Qprice
浮点型(单精度)
4
定价
Qfrequence
整型
4
搜索频率
数据库关系图
为学生进行图书查询建立视图:
V-BookSelect
数据项名
数据类型
长度
别名
是否为空
Bname
字符型
10
书名
否
Bahthor
字符型
10
作者
否
Bpress
字符型
10
出版社
否
Bprice
浮点型(单精度)
4
定价
否
Pno
字符型
10
馆藏地编号
否
Bstate
字符型
10
图书状态
否
Bbstate
字符型
10
借阅状态
否
建立学生、借书卡以及日常事务信息的联系视图,供借书处检查学生详细信息时使用:
V-SCR
数据项名
数据类型
长度
别名
是否为空
Cno
字符型
10
卡号
否
Sname
字符型
10
姓名
Ssex
字符型
2
性别
Sgrade
字符型
10
年级
Sdept
字符型
10
学院
Smajor
字符型
10
专业
Sclass
字符型
10
班级
Cstate
字符型
10
卡状态
否
Rstate
字符型
10
欠书状态
否
Rfine
浮点型(单精度)
10
超时罚款
否
当卡挂失时,不能进行借书业务。凭借学生证可以进行图书注销处理。
建立学生日常事务信息、借阅信息、图书的联系视图,供借书处、还书处、注销处处理相关业务时使用:
V-SBB1
数据项名
数据类型
长度
别名
是否为空
Bname
字符型
10
书名
否
Bahthor
字符型
10
作者
否
Bpress
字符型
10
出版社
否
Bprice
浮点型(单精度)
4
定价
否
Bstate
字符型
10
图书状态
否
Bbstate
字符型
10
借阅状态
否
Bbno
字符型
10
借书代号
否
Bbtime
日期型
8
借书时间
否
Brtime
日期型
8
应还时间
否
Rstate
字符型
10
欠书状态
否
Rfine
浮点型(单精度)
4
超时罚款
否
V-SBB2
数据项名
数据类型
长度
别名
是否为空
Bname
字符型
10
书名
否
Bahthor
字符型
10
作者
否
Bpress
字符型
10
出版社
否
Bprice
浮点型(单精度)
4
定价
否
Pno
字符型
10
馆藏地编号
否
Bstate
字符型
10
图书状态
否
Bbstate
字符型
10
借阅状态
否
Brtime
日期型
10
应还时间
否
Btime
日期型
10
还书时间
Rstate
字符型
10
欠书状态
否
Rfine
浮点型(单精度)
4
超时罚款
否
V-SBB3
数据项名
数据类型
长度
别名
是否为空
Bname
字符型
10
书名
否
Bahthor
字符型
10
作者
否
Bpress
字符型
10
出版社
否
Bprice
浮点型(单精度)
4
定价
否
Pno
字符型
10
馆藏地编号
否
Bstate
字符型
10
图书状态
否
Bbstate
字符型
10
借阅状态
否
Brtime
日期型
10
应还时间
否
Rstate
字符型
10
欠书状态
否
Rfine
浮点型(单精度)
4
超时罚款
否
建立学生的累计借书视图:
V-AllBorrow
数据项名
数据类型
长度
别名
是否为空
Bno
字符型
10
条码号
否
Bname
字符型
10
书名
否
Bahthor
字符型
10
作者
否
Bpress
字符型
10
出版社
否
Bprice
浮点型(单精度)
4
定价
否
Bbno
字符型
10
借书代号
否
Bbtime
日期型
10
借书时间
否
Btime
日期型
10
还书时间
建立借书卡、日常事务信息的联系视图,为罚款处处理相关业务时使用:
V-Fine
数据项名
数据类型
长度
别名
是否为空
Sno
字符型
10
学号
否
Rtime
日期型
10
时间
否
Rfine
浮点型(单精度)
4
超时罚款
否
建立缺书和图书丢失视图,为购书时提供信息:
V-BuyBook1
数据项名
数据类型
长度
别名
是否为空
Qname
字符型
10
书名
否
Qahthor
字符型
10
作者
否
Qpress
字符型
10
出版社
否
Qprice
浮点型(单精度)
4
定价
V-BuyBook2
数据项名
数据类型
长度
别名
是否为空
Bname
字符型
10
书名
否
Bahthor
字符型
10
作者
否
Bpress
字符型
10
出版社
否
Bprice
浮点型(单精度)
4
定价
否
四. 数据库的物理设计
为上一阶段的关系模型选取一个最适合的应用要求的物理结构,即确定存取方法和存储结构。
--创建数据库
Create database Library --图书管理系统
on
(
name='Library',
filename='F:\00000000000000000000000Sql\数据库实训\MY数据库实训\Library.mdf',--路径
size=20mb,
maxsize=200mb,
filegrowth=10%
)
log on
(
name='Librarylog',
filename='F:\00000000000000000000000Sql\数据库实训\MY数据库实训\Librarylog.ldf',--路径
size=5mb,
maxsize=25mb,
filegrowth=5mb
)
--创建基本表
go
use Library
go
create table Student --学生表
(
Sno Char(10) NOT NULL unique, --学号
Sname Char(10),--姓名
Ssex Char(2),--性别
Sgrade Char(10),--年级
Sdept Char(10),--学院
Smajor Char(10),--专业
Sclass Char(10),--班级
primary key(Sno)
)
)
insert into Student values('068109175',')
insert into Student values('068109176',' )
insert into Student values('068109177' ')
insert into Student values('068109178'' )
insert into Student values('068109179' ')
insert into Student values('068109180,' )
go
create table Place--馆藏地
(
Pno char(10) not null unique,--馆藏地编号
Pname char(10) not null,--馆藏地名称
primary key(Pno)
)
insert into Place values('1','1楼')
insert into Place values('2','2楼')
insert into Place values('3','3楼')
insert into Place values('4','4楼')
insert into Place values('5','5楼')
insert into Place values('6','6楼')
insert into Place values('7','7楼')
go
create table Book--图书
(
Bno char(10) not null PRIMARY KEY NONCLUSTERED,--条形码
Bname char(10) not null,--书名
Bahthor char(10) not null,--作者
Bpress char(10) not null,--出版社
Bprice numeric(9) not null,--定价
Pno char(10) not null,--馆藏地编号
Bstate char(10) not null,--图书状态
Bbstate char(10) not null,--借阅状态
foreign key(Pno) references Place(Pno)
)
insert into Book values('1001','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1002','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1003','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1004','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1005','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1006','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1007','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1008','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1009','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1010','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1011','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1012','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1013','诛仙','萧鼎','第八出版社','1','1','在馆','可借')
insert into Book values('1014','诛仙','萧鼎','第八出版社','1','1','丢失','可借')
go
create index 书名
on Book(Bname)
go
create table Card--图书证
(
Cno char(10) not null unique,--卡号
Cstate char(10) not null,--卡状态
Sno char(10) not null,--学号
primary key (Cno),
foreign key(Sno) references Student(Sno)
)
insert into Card values('068109171','正常','068109171')
insert into Card values('068109172','正常','068109172')
insert into Card values('068109173','正常','068109173')
go
use Library
go
create table Jieyue--借阅
(
Cno char(10) not null,--卡号
Bno char(10) not null,--条形码
Bbno char not null,--借书代号
Bbtime date not null,--借书时间
Brtime date not null,--应还时间
Btime date ,--还书时间
primary key(Cno,Bno,Bbno,Bbtime),
foreign key(Cno) references Card(Cno),
foreign key(Bno) references Book(Bno)
)
go
create table LinkBook--缺书
(
Qname char(10) not null,--书名
Qahthor char(10) not null,--作者
Qpress char(10) not null,--出版社
Qprice float(4),--定价
Qfrequence float(4) ,--搜索频率
primary key(Qname,Qahthor,Qpress)
)
go
create table Rountin--学生日常事务日志
(
Cno char(10) not null,--卡号
Rtime datetime,--时间
Rstate int not null,--欠书状态
Rfine numeric(9) ,--超时罚款
primary key(Cno,Rtime),
foreign key(Cno) references Card(Cno)
)
--创建视图
use Library
go
--//在馆图书视图
create view V_BookSelect(Bname,Bahthor,Bpress,Bprice,Pno,Bstate,Bbstate)
as
select Bname,Bahthor,Bpress,Bprice,Pno,Bstate,Bbstate
from Book
where Bstate='在馆'
go
--//所有图书查询
create view V_BookSelectall(Bno,Bname,Bahthor,Bpress,Bprice,Pno,Bstate,Bbstate)
as
select Bno,Bname,Bahthor,Bpress,Bprice,Pno,Bstate,Bbstate
from Book
go
--//所有征订图书
create view V_BookSelectBookLink(Qname,Qahthor,Qpress,Qprice)
as
select Qname,Qahthor,Qpress,Qprice
from LinkBook
go
-- //搜索频率大约的缺书项
create view V_BuyBook1(Qname,Qahthor,Qpress,Qprice)
as
select Qname,Qahthor,Qpress,Qprice
from LinkBook
where Qfrequence>10
go
--//处于丢失状态的图书视图
create view V_BuyBook2(Bname,Bahthor,Bpress,Bprice)
as
select Bname,Bahthor,Bpress,Bprice
from Book
where Bstate='丢失'
go
--//罚款
create view V_Fine(Cno,Sno,Rtime,Rfine)
as
select Card.Cno,Sno,Rtime,Rfine
from Card,Rountin
where Card.Cno=Rountin.Cno
go
--//产看所有
create view V_SBB1(Cno,Bno,Bname,Bahthor,Bpress,Bprice,Bstate,Bbstate,Bbno,Bbtime,Brtime,Btime,Rstate,Rfine)
as
select Jieyue.Cno,Book.Bno,Bname,Bahthor,Bpress,Bprice,Bstate,Bbstate,Bbno,Bbtime,Brtime,Btime,Rstate,Rfine
from Jieyue,Rountin,Book
where Jieyue.Cno=Rountin.Cno
and Jieyue.Bno=Book.Bno
go
--//借书
create view V_SBB2(Cno,Bno,Bname,Bborrowno,Bahthor,Bpress,Bprice,Pno,Bbno,Bstate,Bbstate,Bbtime,Brtime,Btime,Rtime,Rstate,Rfine)
as
select Jieyue.Cno,Book.Bno,Bname,Bbno,Bahthor,Bpress,Bprice,Pno,Bbno,Bstate,Bbstate,Bbtime,Brtime,Btime--,Rtime,Rstate,Rfine
from Jieyue
inner join Book
on Jieyue.Bno=Book.Bno
--inner join Rountin
--on Jieyue.Cno=Rountin.Cno
where Btime is null
go
--//注销
create view V_SBB3(Cno,Bno,Bname,Bahthor,Bpress,Bprice,Pno,Bstate,Bbstate,Brtime,Rstate,Rfine)
as
select Jieyue.Cno,Book.Bno,Bname,Bahthor,Bpress,Bprice,Pno,Bstate,Bbstate,Brtime,Rstate,Rfine
from Jieyue,Rountin,Book
where Jieyue.Cno=Rountin.Cno
and Jieyue.Bno=Book.Bno
go
--//状态
create view V_SCR(Cno,Sname,Ssex,Sgrade,Sdept,Smajor,Sclass,Cstate,Rtime,Rstate,Rfine)
as
select Card.Cno,Sname,Ssex,Sgrade,Sdept,Smajor,Sclass,Cstate,Rtime,Rstate,Rfine
from Student,Card,Rountin
where Student.Sno=Card.Sno
and Card.Cno=Rountin.Cno
go
--//所有借出的书
create view V_allBorrow(Cno,Bname,Bahthor,Bpress,Bprice,Bbno,Bbtime,Btime)
as
select Jieyue.Cno,Bname,Bahthor,Bpress,Bprice,Bbno,Bbtime,Btime
from Book,Jieyue
where Book.Bno=Jieyue.Bno
--创建存取过程
use Library
go
CREATE PROCEDURE 状态查询
@kahao char(10)AS
select *
from V_SCR
where Cno=@kahao
go
CREATE PROCEDURE 借书
@kahao char(10),
@tiaomahao char(10) --条形码号
AS
declare
@cishu1 int,--次数
@benshu1 int,--
@shijian datetime,--时间
@cishu int,--
@benshu int--本数
Set @cishu1=0
set @benshu1=0
declare cursor_bbtime CURSOR scroll for select Bbno from V_SBB2 where Cno=@kahao and Bno=@tiaomahao
declare cursor_rstate CURSOR scroll for select Rstate from Rountin where Cno=@kahao
open cursor_bbtime
open cursor_rstate
fetch first from cursor_bbtime into @cishu1 -- 当前书
fetch first from cursor_Rstate into @benshu1 -- 本数
close cursor_bbtime
close cursor_rstate
deallocate cursor_bbtime
deallocate cursor_rstate
set @cishu=@cishu1+1
set @benshu=@benshu1+1
set @shijian=GETDATE() --时间
update Book
set Book.Bbstate='不可借'
where @kahao in(select Cno
from card
) and Bno=@tiaomahao
insert into Jieyue(bbno,cno,bno,Bbtime,brtime) values(@cishu,@kahao,@tiaomahao,@shijian,DATEADD(day, 30, @shijian))--借阅信息
insert into Rountin(cno,Rstate,Rtime) values(@kahao,@benshu,@shijian)--更新事务日志
select distinct Cno,Bno,Bname,Bborrowno,Bahthor,Bpress,Bprice,Pno,Bbno,Bstate,Bbstate,Bbtime,Brtime,Rtime,Rstate,Rfine
from V_SBB2
where Cno=@kahao
go
CREATE PROCEDURE 还书
@kahao char(10),
@tiaomahao char(10)
AS
declare
@time datetime,
@benshu int,
@benshu1 int
declare cursor_time CURSOR scroll for select Brtime from V_SBB2 where Cno=@kahao and Bno=@tiaomahao
declare cursor_Rstate CURSOR scroll for select Rstate from Rountin where Cno=@kahao
open cursor_time
open cursor_Rstate
fetch first from cursor_time into @time
fetch cursor_Rstate into @benshu
set @benshu1=@benshu-1
close cursor_time
close cursor_Rstate
deallocate cursor_time
deallocate cursor_rstate
update Rountin set Rfine=DATEDIFF(day,@time,GETDATE())*0.03
where Cno=@kahao and @tiaomahao in (select Bno from Book) and DATEDIFF(day,@time,GETDATE())>0
update Book set Bbstate='可借'
where @kahao in(select Cno
from card
)
and Bno=@tiaomahao
update Jieyue set Btime=GETDATE()
where Cno=@kahao and Bno=@tiaomahao
update Rountin set Rstate=@benshu1
where Cno=@kahao
select distinct Cno,Sname,Ssex,Sgrade,Sdept,Smajor,Sclass,Cstate,Rtime,Rstate,Rfine
from V_SCR
go
CREATE PROCEDURE 注销
@kahao char(10),
@tiaomahao char(10)
AS
declare
@time datetime,
@benshu int,
@benshu1 int,
@price numeric
declare cursor_time CURSOR scroll for select Brtime from V_SBB3 where Cno=@kahao and Bno=@tiaomahao
declare cursor_Rstate CURSOR scroll for select Rstate from Rountin where Cno=@kahao
declare cursor_price CURSOR scroll for select Bprice from Book where Bno=@tiaomahao
open cursor_time
open cursor_Rstate
open cursor_price
fetch cursor_time into @time
fetch cursor_Rstate into @benshu
fetch cursor_price into @price
set @benshu1=@benshu-1
close cursor_time
close cursor_Rstate
close cursor_price
deallocate cur
展开阅读全文