1、言简意赅,远见卓识,望君采纳,谢谢!删除水印可,编辑页眉,选中水印,点击删除。图书管理系统数据库设计1、系统简介图书管理是每个图书馆都需要进行的工作。一个设计良好的图书管理系统数据库能够给图书管理带来很大的便利。2、需求分析图书管理系统的需求定义为:1.学生可以直接通过借阅终端来查阅书籍信息,同时也可以查阅自己的借阅信息。2.当学生需要借阅书籍时,通过账号密码登陆借阅系统,借阅系统处理学生的借阅,同时修改图书馆保存的图书信息,修改被借阅的书籍是否还有剩余,同时更新学生个人的借阅信息。3.学生借阅图书之前需要将自己的个人信息注册,登陆时对照学生信息。4.学生直接归还图书,根据图书编码
3、yOK,0rowsaffectedRecords:0Duplicates:0Warnings:0mysqlaltertablestudentaddindexindex_name(stu_namedesc);QueryOK,0rowsaffectedRecords:0Duplicates:0Warnings:0mysql栏穆蠡l外短触发给选项注蟀SQL烫S米弓也NormalNomnal索弓方去BTREEBTREES栏位indlei_idiridenarnestu_r3rnebook:1.为book_id创建索引,升序排列sql:c
4、reateindexindex_bidonbook(book_id);2.为book_record创建索引,以便方便查询图书的登记日期信息,升序:sql:createindexindex_brecordonbook(book_record);插入索引的操作和结果如下所示:mysqlcreateindexindex_bidonbook(book_id);QueryOK,0rowsaffectedRecords:0Duplicates:0Warnings:0mysqlcreateindexindex_brecordonbook(book_r
5、ecord);QueryOK,0rowsaffectedRecords:0Duplicates:0Warnings:0栏侵索引外特融意署选项注降QL碰虑至弓后去BTREEBTREE当栏位需引樊型book_idhlcrmlmdejcbrecordbookrecordNornnalborrow:1.为stu_id和book_id创建多列索引:sql:createindexindex_sid_bidonborrow(stu_idasc,book_idasc);插入索引的操作和结果如下所示:mysqlcreateindexindex_sid_bid
6、onborrow(stu_idasc,book_idasc);QueryOK,0rowsaffectedRecords:0Duplicates:0Warnings:0栏构索另外键融妗器领注理弓QL逆真索弓I昊里NormalNormal塞弓后去BTREEBTREE昌栏位oookidindex_sid_bidstu_idtbookidreturn_table:1.为stu_id和book_id创建多列索引:sql:createindexindex_sid_bidonreturn_table(stu_idasc,book_idasc);插
7、入索引的操作和结果如下所示:mysqlcreateindexindex_sid_bid_ronreturn_table(stu_idasc,book_idasc);QueryOK,0rowsaffectedRecords:0Duplicates:0Warnings:0栏位素夕围触发言谈注薛QL预览stuid.bookidNormal案W方汰BTREEticket:1.为stu_id和book_id创建多列索引:sql:createindexindex_sid_bidonticket(stu_idasc,book_idasc);插
8、入索引的操作和结果如下所示:mysqlcreateindexindex_sid_bidonticket(stu_idasc,book_idasc);QueryOK,0rowsaffectedRecords:0Duplicates:0Warnings:0栏化塞引外凝倏宜器SIG注毒GL侬manager:奏引美型Normal室引方法BTREE1.为manager_id创建索引:sql:createindexindex_midonmanager(manager_id);插入索引的操作和结果如下所示:mysqlcreateindexind
9、ex_midonmanager(manager_id);QueryOK,0rowsaffectedRecords:0Duplicates:0Warnings:0栏位裳弓外镇触箕善正当主售WOL药监managerjd索引法聚弓方市NcrmalBTREE4、设计视图给出在各表上建立的视图以及使用的语句。1.在表student上创建计算机专业(cs)学生的视图stu_cs:sql:createviewstu_csasselect*fromstudentwherepro=cs;操作和结果:mysqlcreateviewstu_csass
10、elect*fromstudentwherestu_pro=cs;QueryOK,0rowsaffectedstu_id5tuname5tu_agestu_pro5tu_gradesttijntegrityI5tu_am20cs201412stubm21匚5201413占tucf20cs201414studfigCS2014155tUcrn2。G201412.在表student,borrow和book上创建借书者的全面信息视图stu_borrow:sql:createviewstu_borrowasselectstudent.stu_id,
11、book.book_id,student.stu_name,book.book_name,borrow_dateadddate(borrow_date,30)expect_return_datefromstudent,book,borrowwherestudent.stu_id=borrow.stu_idandbook.book_id=borrow.book_id;操作和结果:mysqlcreateviewstu_borrowasselectstudent.stu_id,book.book_id,student.stu_name,book.boo
12、k_name,borrow_dateadddate(borrow_date,30)expect_return_datefromstudent,book,borrowwherestudent.stu_id=borrow.stu_idandbook.book_id=borrow.book_id;QueryOK,0rowsaffectedstu_idbook_idlttu_namebook_nameborrow_dateexpect_return_date1computernetwo2016-12-2817:072017-OV2717iO7;103.
13、创建类别1的所有图书的视图cs_book:sql:createviewcs_bookasselect*frombookwherebook.book_sortin(selectbook_frombook_sortwheresort_id=1);操作和结果显示:mysqlcreateviewcs_bookasselect*frombookwherebook.book_sortin(selectbook_sort.sort_namefrombook_sortwheresort_id=1);QueryOK,0r
14、owsaffectedbook汨booknanniebDoikauthorhootjjubbookjiLimbdCKSCrTbock_rerccmpiJternefevcrtcsuthQr3pub.a1cs2016-12.281665:572computeropcrcticnauthorbpubb1c201B12-281615gl393mf&rrndtiafi.己outlhr_cpub_fl1ca2015-12-2ST515&374softwareengineer3gauthDr_dpub_d1cs之川,也之815:55:1054一phslearnin
15、g3utbor_epuba1C52016-12-2515:59556cprcgrannnningiauthorpub日小7sqlamthgr_dPb_c1a201悟端17rfXM74.创建个人所有借书归还纪录视图stu_borrow_return:sql:createviewstu_borrow_returnasselectstudent.stu_id,student.stu_name,book.book_id,book.book_name,return_table.borrow_date,return_table.return_datefromstudent,book,
16、return_tablewherestudent.stu_id=return_table.stu_idandbook.book_id=return_table.book_id;stujdstu_nameIjookjdlQck_nameborrow_d3tereturndwtEstu_a1computernetwork2016-10-1617rD7:182016-12-2916t56;505、设计触发器给出在各表上建立的触发器以及使用的语句。1.设计触发器borrow,当某学生借书成功后,图书表相应的图书不在架上,变为sql:createtriggerborro
17、wafterinsertonborrowforeachrowbeginupdatebooksetbook_num=book_num-1wherebook_id=new.book_id;end操作与结果显示:mysqldelimiter$mysqlcreatetriggertrigger_borrow-afterinsertonborrow-foreachrow-begin-updatebooksetbook_num=book_num-1-wherebook_id=new.book_id;-end-$Quer
18、yOK,0rowsaffected在插入表borrow之前,book_id=1的图书还在架上,为1:book_idbcok_namebook_authorbookpubbcok_numboolksort1computernetworkduthor_apub31学生1借了这本书后,在borrow中插入了一条记录:stujdbookidborrow_d3te201612-2B17:07在borrow中插入这条记录后,book_id=1的图书,不在架上,为0:hookjdbock_rramebook_dudiorbook_pubbcokn
19、urnbook_ort1computernetworkaunor_apub_a0g0:LciDk_record201&-1220沅55;tcok_reeord2.设计触发器trigger_return,还书成功后,对应的书籍book_num变为1:sql:createtriggertrigger_returnafterinsertonreturntableforeachrowbeginupdatebooksetbook_num=book_num+1wherebook_id=new.book_id;end还书时在return_table插
21、eventJobonscheduleevery1DAY/*每天触发*/oncompletionPRESERVEdocallproc_gen_ticket(getdate();/*调用存储过程*/setglobalevent_scheduler=1;altereventeventJoboncompletionpreserveenable;/*开启定时器*/操作和结果显示:1).学生1借了图书1,生成借书记录stu_borrow视图,如下:stujdbookid5tu_namebooknameborrowdateexpect_re
22、turn_date1stu.acompirternetwo2016-12-2817072017-01-2717;O7;182).当他在1月27日前还书时,没有生成罚单:5tuidbookidreturn_date2016-12-3021stuidbookidaverdarteticketfee(Null3).当他在1月27日后还书时,生成罚单:stu_idbock_idreturr_date2D17-O2-2S21:rtu_idbookidover-dateticket_fee13224.设计触发器trigger_credit,若处罚
23、记录超过30条,则将这个学生的诚信级设置为0,下次不允许借书:sql:createtriggertrigger_creditafterinsertonticketforeachrowbeginif(selectcount(*)fromticketwherestu_id=new.stujd)30thenupdatestudentsetstu_integrity=0wherestu_id=new.stu_id;endif;end操作和结果显示,测试时选择插入ticket项大于3,因为30太大了,不容易测试:学生1超过3次超期归还图书后,产生了4
24、条罚单:stujdbook_idover_dateticketjee11323123112421531此时触动触发器trigger_credit,将学生1的诚信级设置为0:stujdtu_nameitu_agestu_prostu_gradestu_in-tegritynuam20C5201402stu_bm21CS20141四、应用程序设计与编码实现1、系统实现中存储函数和存储过程的设计要求给出功能描述和代码。1.设计存储过程,产生罚单proc_gen_ticket:当日期超过预定归还日期时,产生罚单,并将记录写入表ticket中,这个存储过程在定时器eventJob中调用:sql
25、:createprocedureproc_gen_ticket(incurrentdatedatetime)BEGINdeclarecur_datedatetime;setcur_date=currentdate;replaceintoticket(stu_id,book_id,over_date,ticket_fee)selectstu_id,book_id,datediff(cur_date,stu_borrow.expect_return_date),0.1*datediff(cur_date,stu_borrow.expect_return_date)fr
26、omstu_borrowwherecur_datestu_borrow.expect_return_date;end操作和结果显示:1).学生1借了图书1,生成借书记录stu_borrow视图,如下:stujclbookidstu_namebooknameborrowdateexpect_retum_date1stu_acomputernetwo201&-12-281707201701-2717:07:102).当他在1月27日前还书时,没有生成罚单:5tu_idbookidre-turn_date2016-12-i02111stujdboo
27、kidoverdarteticketfee(Null)(Mull);3).当他在1月27日后还书时,生成罚单:stujdbookidreturrdate2D17-02-23Z1:stu_idbook_idover-dateticket_fee113232.设计学生注册信息存储过程:学生注册信息stu_registersql:createprocedurestu_register(instu_idint,instu_namevarchar(20),instu_sexvarchar(20),instu_ageint,instu_provar
28、char(20),instu_gradevarchar(20)begininsertintostudent(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);end3.设计管理员注册信息存储过程:ma_registersql:createprocedurema_register(inma_idint,inma_namevarchar(20),inma_ageint,inma
29、_phoneint)BEGINinsertintomanagervalues(ma_id,ma_name,ma_age,ma_phone);END4.借书过程的实现:1)设计存储函数,func_get_credit,返回学生的诚信级:createfunctionfunc_get_credit(stu_idint)returnsintbeginreturn(selectstu_integrityfromstudentwherestudent.stu_id=stu_id);end2)设计存储函数,func_get_booknum,返回书籍是否在架
30、上:createfunctionfunc_get_booknum(book_idint)returnsintbeginreturn(selectbook_numfrombookwherebook.book_id=book_id);end3)设计存储过程proc_borrow,调用func_get_credit和func_get_booknum,判断这个学生诚信度和书籍是否在架上,若为真,则借书成功,在borrrow表中插入纪录;否则提示失败:createprocedureproc_borrow(instu_idint,inbook_idi
31、nt,inborrow_datedatetime)beginiffunc_get_credit(stu_id)=1andfunc_get_booknum(book_id)=1theninsertintoborrowvalues(stu_id,book_id,borrow_date);elseselectfailedtoborrow;endif;end实验操作与结果显示:borrow纪录为空:rtuidbookidborrowdate(Null)执行函数,学生1借图书2:callproc_borrow(1,2,now();学生1的诚信级为0
32、:stuidstu_narieStLJE&K5tu_agestj_prpstugradestuJntegnty*KIstuaIYI20n20140借书失败:信息结果1版兄状态failedtoborrowfailedtoborrow修改学生1诚信级为1:stujdstu_nsmestu_sexstu_agestuprostu_gradestujintegrity1Stu_BmCS20141此时借书成功:stu_idbookidborrowdate22016-12-2917:315.还书存储过程proc_return:当还书时,查看是否书是否超期,
33、即查询ticket表项,当发现超期,提示交罚单后再次还书,如没有超期,则纪录归还项目到return_table中,并且删除借书纪录(以免还书后定时器仍然扫描这个纪录):sql:createprocedureproc_return(instu_idint,inbook_idint,inreturn_datedatetime)beginDECLAREborrowdatedatetime;if(selectpayofffromticketwhereticket.stu_id=stu_idandticket.book_id=book_id)=1th
34、en/*判断是否交了罚单,1表示没有交*/selectpleasepayofftheticket;else/*纪录归还项目到return_table中,并且删除借书纪录*/setborrowdate=(selectborrow_datefromborrowwhereborrow.stu_id=stu_idandborrow.book_id=book_id);insertintoreturn_tablevalues(stu_id,book_id,borrowdate,return_date);deletefromborrowwhereb
35、orrow.stu_id=stu_idandborrow.book_id=book_id;endif;end实验操作与结果显示:学生1借了图书2:stujdbookjdborrow_date22016-12-2Q1市1超期产生了罚单,没有交罚单,payoff=1stujdbookjdove-r_dateticketJeepayoff1444012N1132221此时调用还书过程:callproc_return(1,2,now();提示交罚单:pleasepayofftheticlc&tpleasepayofftheticket交罚单,调用pro
36、c_payoff:callproc_payoff(1,2);交罚单成功,payoff=0;stuidbookidover_dateticketfeepayoffMl14440i22830i32221此时再次调用还书过程:callproc_return(1,2,now();还书成功,在return_table生成了还书纪录:stujdbookJdborrow_datereturndate12016*10-1617:07201612-291651220H-12-2S17;312015-12-2919;46.交罚单存储过程:修改罚单中payoff段为0,表明
37、罚单已交:createprocedureproc_payoff(instuidint,inbookidint)beginupdateticketsetpayoff=0whereticket.stu_id=stuidandticket.book_id=bookid;selectsucceed;end交罚单,调用proc_payoff:callproc_payoff(1,2);交罚单成功,payoff=0;2、功能实现按各功能模块进行描述。要求:画出流程图并给出实现代码。创建学生统一账户,账户名:student_account,并且授予权限:
38、sql:createuserstudent_accountlocalhost;grantinsert,selectonstudenttostudent_accountlocalhost;grantselectonbooktostudent_accountlocalhost;grantinsert,selectonborrowtostudent_accountlocalhost;grantinsert,selectonreturn_tabletostudent_accountlocalhost;grantselectontickettostu