系统概述
1系统简介
图书理图书馆需进行工作设计良图书理系统数库够图书理带便利
2需求分析
图书理系统需求定义:
1学生直接通阅终端查阅书籍信息时查阅阅信息
2学生需阅书籍时通账号密码登陆阅系统阅系统处理学生阅时修改图书馆保存图书信息修改阅书籍否剩余时更新学生阅信息
3学生阅图书前需信息注册登陆时学生信息
4学生直接图书根图书编码修改阅信息
5理员登陆理系统修改图书信息增加者删图书信息
6理员注销学生信息
通需求定义画出图书理系统数流图:
数流图
二系统功设计
画出系统功模块图文字功模块进行详细介绍
系统功模块图:
三数库设计方案图表
1系统ER模型
总体ER图:
精细化局部ER图:
学生阅ER图:
理员ER图:
2设计表
出设计表名结构表设计完整性约束
student:
列名
数类型
否空性质
说明
stu_id
int
not null PK
标明学生唯学号
stu_name
varchar
not null
学生姓名
stu_sex
varchar
not null
学生性
stu_age
int
not null
学生年龄
stu_pro
varchar
not null
学生专业
stu_grade
varchar
not null
学生年级
stu_integrity
int
not nulldefault1
学生诚信级
book
列名
数类型
否空性质
说明
book_id
int
not null PK
唯书籍序号
book_name
varchar
not null
书籍名称
book_author
varchar
not null
书籍作者
book_pub
varchar
not null
书籍出版社
book_num
int
not null
书籍否架
book_sort
varchar
not null
书籍分类
book_record
datatime
null
书籍登记日期
book_sort
列名
数类型
否空性质
说明
sort_id
varchar
not null PK
类型编号
sort_name
varchar
not null
类型名称
borrow存储学生书信息
列名
数类型
否空性质
说明
student_id
varchar
not null PK
学生编号
book_id
varchar
not null PK
书籍编号
borrow_date
datatime
null
书时间
expect_return_date
datetime
null
预期时间
return_table存储学生信息
列名
数类型
否空性质
说明
student_id
varchar
not null PK
学生编号
book_id
varchar
not null PK
书籍编号
borrow_date
datetime
null
书时间
return_date
datatime
null
实际书时间
ticket存储学生罚单信息
列名
数类型
否空性质
说明
student_id
varchar
not null PK
学生编号
book_id
varchar
not null PK
书籍编号
over_date
int
null
超期天数
ticket_fee
float
null
处罚金额
manager
列名
数类型
否空性质
说明
manager_id
varchar
not null PK
理员编号
manager_name
varchar
not null
理员姓名
manager_age
varchar
not null
理员年龄
manager_phone
varchar
not null
理员电话
3设计索引
出表建立索引语句
student:
1stu_id创建索引升序排序
sqlcreate index index_id on student(stu_id asc)
2stu_name创建索引降序排序
sqlalter table student add index index_name(stu_name desc)
插入索引操作结果示:
mysql> create index index_id on student(stu_id asc)
Query OK 0 rows affected
Records 0 Duplicates 0 Warnings 0
mysql> alter table student add index index_name(stu_name desc)
Query OK 0 rows affected
Records 0 Duplicates 0 Warnings 0
mysql>
book
1book_id创建索引升序排列
sqlcreate index index_bid on book(book_id)
2book_record创建索引便方便查询图书登记日期信息升序:
sqlcreate index index_brecord on book(book_record)
插入索引操作结果示:
mysql> create index index_bid on book(book_id)
Query OK 0 rows affected
Records 0 Duplicates 0 Warnings 0
mysql> create index index_brecord on book(book_record)
Query OK 0 rows affected
Records 0 Duplicates 0 Warnings 0
borrow
1stu_idbook_id创建列索引:
sqlcreate index index_sid_bid on borrow(stu_id asc book_id asc)
插入索引操作结果示:
mysql> create index index_sid_bid on borrow(stu_id asc book_id asc)
Query OK 0 rows affected
Records 0 Duplicates 0 Warnings 0
return_table
1stu_idbook_id创建列索引:
sqlcreate index index_sid_bid on return_table(stu_id asc book_id asc)
插入索引操作结果示:
mysql> create index index_sid_bid_r on return_table(stu_id asc book_id asc)
Query OK 0 rows affected
Records 0 Duplicates 0 Warnings 0
ticket
1 stu_idbook_id创建列索引:
sqlcreate index index_sid_bid on ticket(stu_id asc book_id asc)
插入索引操作结果示:
mysql> create index index_sid_bid on ticket(stu_id asc book_id asc)
Query OK 0 rows affected
Records 0 Duplicates 0 Warnings 0
manager
1manager_id创建索引:
sqlcreate index index_mid on manager(manager_id)
插入索引操作结果示:
mysql> create index index_mid on manager(manager_id)
Query OK 0 rows affected
Records 0 Duplicates 0 Warnings 0
4设计视图
出表建立视图语句
1表student创建计算机专业(cs)学生视图stu_cs:
sql create view stu_cs as
select *
from student
where pro cs’
操作结果:
mysql> create view stu_cs as
select *
from student
where stu_pro 'cs'
Query OK 0 rows affected
2 表student borrowbook创建书者全面信息视图stu_borrow:
sql create view stu_borrow as
select studentstu_id bookbook_id studentstu_name bookbook_name borrow_dateadddate(borrow_date30) expect_return_date
from student book borrow
where studentstu_id borrowstu_id and bookbook_id borrowbook_id
操作结果:
mysql> create view stu_borrow as
select studentstu_id bookbook_id studentstu_name bookbook_name borrow_dateadddate(borrow_date30) expect_return_date
from student book borrow
where studentstu_id borrowstu_id and bookbook_id borrowbook_id
Query OK 0 rows affected
3创建类1图书视图cs_book:
sql create view cs_book as
select *
from book
where bookbook_sort in
(select book_sortsortname
from book_sort
where sort_id 1)
操作结果显示:
mysql> create view cs_book as
select *
from book
where bookbook_sort in
(select book_sortsort_name
from book_sort
where sort_id 1)
Query OK 0 rows affected
4创建书纪录视图stu_borrow_return
sql
create view stu_borrow_return as
select studentstu_id studentstu_name bookbook_id bookbook_namereturn_tableborrow_datereturn_tablereturn_date
from student book return_table
where studentstu_id return_tablestu_id and bookbook_id return_tablebook_id
5设计触发器
出表建立触发器语句
1设计触发器borrow 某学生书成功图书表相应图书架变0:
sql
create trigger borrow
after insert on borrow
for each row
begin
update book set book_num book_num – 1
where book_id newbook_id
end
操作结果显示:
mysql> delimiter
mysql> create trigger trigger_borrow
> after insert on borrow
> for each row
> begin
> update book set book_num book_num 1
> where book_id newbook_id
> end
>
Query OK 0 rows affected
插入表borrow前book_id 1 图书架1:
学生1书borrow中插入条记录:
borrow中插入条记录book_id 1图书架0:
2设计触发器trigger_return 书成功应书籍book_num变1:
sql
create trigger trigger_return
after insert on return_table
for each row
begin
update book set book_num book_num + 1
where book_id newbook_id
end
书时return_table插入表项:
时图书架:
3定义定时器(事件)eventJob天动触发次扫描视图stu_borrow发现前预期时间前时间判断超期生成处罚记录定时器天定时触发存储程proc_gen_ticket:
sql
create event if not exists eventJob
on schedule every 1 DAY *天触发*
on completion PRESERVE
do call proc_gen_ticket(getdate()) *调存储程*
set global event_scheduler 1
alter event eventJob on completion preserve enable *开启定时器*
操作结果显示:
1) 学生1图书1生成书记录stu_borrow视图:
2) 1月27日前书时没生成罚单:
3) 1月27日书时生成罚单:
4设计触发器trigger_credit处罚记录超30条学生诚信级设置0次允许书:
sql
create trigger trigger_credit
after insert on ticket
for each row
begin
if (select count(*) from ticket where stu_idnewstu_id)>30 then
update student set stu_integrity 0 where stu_id newstu_id
end if
end
操作结果显示测试时选择插入ticket项330太容易测试:
学生1超3次超期图书产生4条罚单:
时触动触发器trigger_credit学生1诚信级设置0:
四应程序设计编码实现
1系统实现中存储函数存储程设计
求出功描述代码
1 设计存储程产生罚单proc_gen_ticket:
日期超预定日期时产生罚单记录写入表ticket中存储程定时器eventJob中调:
sql:
create procedure proc_gen_ticket(in currentdate datetime)
BEGIN
declare cur_date datetime
set cur_date currentdate
replace into ticket(stu_id book_id over_date ticket_fee)
select stu_id book_id datediff(cur_datestu_borrowexpect_return_date)01*datediff(cur_datestu_borrowexpect_return_date)
from stu_borrow
where cur_date>stu_borrowexpect_return_date
end
操作结果显示:
1) 学生1图书1生成书记录stu_borrow视图:
2) 1月27日前书时没生成罚单:
3) 1月27日书时生成罚单:
2设计学生注册信息存储程:学生注册信息stu_register
sql
create procedure stu_register(in stu_id int in stu_name varchar(20) in stu_sex varchar(20) in stu_age int in stu_pro varchar(20) in stu_grade varchar(20))
begin
insert into student(stu_id stu_name stu_sex stu_age stu_pro stu_grade)
values(stu_id stu_name stu_sex stu_age stu_pro stu_grade)
end
3 设计理员注册信息存储程:ma_register
sql
create procedure ma_register(in ma_id int in ma_name varchar(20) in ma_age int in ma_phone int)
BEGIN
insert into manager
values(ma_id ma_name ma_age ma_phone)
END
4 书程实现
1) 设计存储函数func_get_credit返回学生诚信级:
create function func_get_credit(stu_id int) returns int
begin
return(select stu_integrity from student where studentstu_id stu_id)
end
2) 设计存储函数func_get_booknum返回书籍否架:
create function func_get_booknum(book_id int) returns int
begin
return(select book_num from book where bookbook_id book_id)
end
3) 设计存储程proc_borrow调func_get_creditfunc_get_booknum判断学生诚信度书籍否架真书成功borrrow表中插入纪录否提示失败:
create procedure proc_borrow(in stu_id int in book_id int in borrow_date datetime)
begin
if func_get_credit(stu_id) 1 and func_get_booknum(book_id) 1 then
insert into borrow
values(stu_id book_id borrow_date)
else
select 'failed to borrow'
end if
end
实验操作结果显示:
borrow纪录空:
执行函数学生1图书2:
call proc_borrow(12now())
学生1诚信级0:
书失败:
修改学生1诚信级1:
时书成功:
5 书存储程proc_return:
书时查否书否超期查询ticket表项发现超期提示交罚单次书没超期纪录项目return_table中删书纪录(免书定时器然扫描纪录):
sql:
create procedure proc_return(in stu_id int in book_id int in return_date datetime)
begin
DECLARE borrowdate datetime
if (select payoff from ticket where ticketstu_id stu_id and ticketbook_idbook_id) 1 then *判断否交罚单1表示没交*
select 'please pay off the ticket'
else *纪录项目return_table中删书纪录*
set borrowdate (select borrow_date from borrow where borrowstu_id stu_id and borrowbook_id book_id)
insert into return_table
values(stu_id book_id borrowdate return_date)
delete from borrow
where borrowstu_id stu_id and borrowbook_id book_id
end if
end
实验操作结果显示:
学生1图书2:
超期产生罚单没交罚单payoff1:
时调书程:
call proc_return(1 2 now())
提示交罚单:
交罚单调proc_payoff
call proc_payoff(1 2)
交罚单成功payoff 0
时次调书程:
call proc_return(1 2 now())
书成功return_table生成书纪录:
6 交罚单存储程:
修改罚单中payoff段0表明罚单已交:
create procedure proc_payoff(in stuid int in bookid int)
begin
update ticket
set payoff 0
where ticketstu_id stuid and ticketbook_id bookid
select succeed’
end
交罚单调proc_payoff
call proc_payoff(1 2)
交罚单成功payoff 0
2功实现
功模块进行描述求:画出流程图出实现代码
l 创建学生统账户账户名:student_account授予权限:
sql:
create user 'student_account'@'localhost'
grant insertselect on student to 'student_account'@'localhost'
grant select on book to 'student_account'@'localhost'
grant insertselect on borrow to 'student_account'@'localhost'
grant insertselect on return_table to 'student_account'@'localhost'
grant select on ticket to 'student_account'@'localhost'
l 创建理员统账户账户名:manager_account 授予全部权限:
sql:
create user 'manager_account'@'localhost' identified by '123'
grant all on library_management to 'manager_account'@'localhost'
l 查询图书信息
书名查找:
select * from book where book_name sql’
作者查找:
select * from book where book_author author’
l 书功 proc_borrow(in stu_id int in book_id int in borrow_date datetime)
果接书架学生诚信级1书
call proc_borrow(1 1 now())
命令行操作:
表borrow:
视图stu_borrow
表book:
l 书功 proc_return(in stu_id int in book_id int in return_date datetime)
call proc_return(1 1 now())
命令行操作:
表return_table
表borrow:
表book:
l 交罚单功proc_payoff(in stuid int in bookid int)
call proc_payoff(11)
实验操作结果见节:6 交罚单存储程
l 理员添加图书:
insert into book
values(…)
操作结果:
l 理员删图书:
delete from book
where (condition)
l 理员注销学生信息:
delete from student
where (condition)
l 理员恢复学生诚信级:
update student
set stu_integrity1
where (condition)
学生书流程图:
理员理流程图:
数库设计结果:
五实体会
写
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档