1、数据库大作业目录1.项目设计目的与内容 31.1目的 3.方案图表设计 32.1 E-R图 33.数据库源代码 53.1数据库建立 63.2数据初始化 74.结果数据处理 104.1单表查询 104.2还书操作 124.3借书操作 134.4书籍状态 144.5读者状态 155.结束语 165.1课程设计心得 16图书库存管理系统一、 实验目的及内容目的:1. 掌握计算机管理信息系统设计的一般方法,主要包括系统分析、系统设计的组织和实施。2. 关系型数据库管理系统的编程技术,并能独立完成一般小系统的程序设计、调试运行等工作。3. 培养把所学知识运用到具体对象,并能求出解决方案的能力。二、 图书
2、管理系统 E-R图:2.1 E-R图根据1)所要实现的功能设计,可能建立它们之间的关系,进而实现逻辑结构功能。图书管理信息系统可以划分的实体有:书籍类别信息实体、读者信息实体、书籍信息实体、借阅记录信息实体,归还记录信息实体。用E-R图一一描述这些实体。2.1.1类别实体E-R图:图2-1类别实体E-R图2.1.2读者信息实体E-R图:图2-2 读者信息实体E-R图2.1.3信息实体E-R图:图2-3信息实体E-R图2.1.4.记录信息实体E-R图:图2-4 记录信息实体E-R图2.1.5记录信息实体E-R图:图2-5记录信息实体E-R图2.1.5. 总的信息实体E-R图:总的信息实体E-R图
3、三、数据库源代码3.1数据库建立3.1.1创建数据库USE masterGOCREATE DATABASE librarysystemON ( NAME = librarysystem, FILENAME = d:librarysystem.mdf, SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5 )LOG ON( NAME = library, FILENAME = d:librarysystem.ldf, SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB )GO3.1.2书本类别表建立create table book
4、_style( bookstyleno varchar(30) primary key, bookstyle varchar(30)3.1.3创建书库表create table system_books( bookid varchar(20) primary key, bookname varchar(30) Not null, bookstyleno varchar(30) Not null, bookauthor varchar(30), bookpub varchar(30) , bookpubdate datetime, bookindate datetime , isborrowed
5、 varchar (2) ,foreign key (bookstyleno) references book_style (bookstyleno),)3.1.4借书证表建立create table system_readers ( readerid varchar(9)primary key, readername varchar(9)not null , readersex varchar(2) not null, readertype varchar(10), regdate datetime)3.1.5借书记录表建立create table borrow_record( bookid
6、 varchar(20) primary key, readerid varchar(9), borrowdate datetime, foreign key (bookid) references system_books(bookid), foreign key (readerid) references system_readers(readerid),)3.1.6还书记录表建立create table return_record( bookid varchar(20) primary key, readerid varchar(9), returndate datetime, fore
7、ign key (bookid) references system_books(bookid), foreign key (readerid) references system_readers(readerid)3.2数据初始化3.2.1将书籍类别加入表book_style中insert into book_style(bookstyleno,bookstyle)values(1,人文艺术类) insert into book_style(bookstyleno,bookstyle)values(2,自然科学类)insert into book_style(bookstyleno,book
8、style)values(3,社会科学类)insert into book_style(bookstyleno,bookstyle)values(4,图片艺术类)insert into book_style(bookstyleno,bookstyle)values(5,政治经济类)insert into book_style(bookstyleno,bookstyle)values(6,工程技术类)insert into book_style(bookstyleno,bookstyle)values(7,语言技能类)3.2.2将已有的图书加入system_books表中(定义相同的作者出版社的
9、书本编号不一样)insert into system_books(bookid ,bookname, bookstyleno,bookauthor,bookpub,bookpubdate, bookindate, isborrowed )values(00125415152,计算机组成原理,6,王爱英,清华大学出版社,2001-01-03,2003-11-15,1);insertinto system_books(bookid ,bookname, bookstyleno,bookauthor,bookpub,bookpubdate, bookindate, isborrowed )value
10、s(00125415153,计算机组成原理,6,王爱英,清华大学出版社,2001-01-03,2003-11-15,1);insert into system_books(bookid ,bookname, bookstyleno,bookauthor,bookpub, bookpubdate,bookindate, isborrowed )values(00456456,数据库原理,6,萨师煊,高等教育出版社,2007-07-02,2007-09-15,1);insert into system_books(bookid ,bookname, bookstyleno,bookauthor,b
11、ookpub,bookpubdate, bookindate, isborrowed )values(12215121,C程序设计,6,谭浩强,清华大学出版社,2002-04-02,2004-03-14,1);insert into system_books(bookid ,bookname, bookstyleno,bookauthor,bookpub, bookpubdate,bookindate, isborrowed )values(9787308020558,计算机体系结构,6,石教英,浙江大学出版社,2004-10-03,2006-11-15,1);insert into syst
12、em_books(bookid ,bookname, bookstyleno,bookauthor,bookpub, bookpubdate,bookindate, isborrowed )values(45456141414,数据结构(C语言版),6,吴伟民,严蔚敏,清华大学出版社,2002-06-28,2004-01-21,1);insert into system_books(bookid ,bookname, bookstyleno,bookauthor,bookpub, bookpubdate,bookindate, isborrowed )values(5455515,中华历史50
13、00年,1,吴强,北京大学出版社,2005-04-03,2006-05-15,1);insert into system_books(bookid ,bookname, bookstyleno,bookauthor,bookpub, bookpubdate,bookindate, isborrowed )values(015115,古代埃及,3,赵文华,北京大学出版社,2001-02-02,2002-09-15,1);insert into system_books(bookid ,bookname, bookstyleno,bookauthor,bookpub, bookpubdate,bo
14、okindate, isborrowed )values(1514514,日本文化,1,吴小鹏,北京大学出版社,2002-04-02,2004-03-14,1);insert into system_books(bookid ,bookname, bookstyleno,bookauthor,bookpub, bookpubdate,bookindate, isborrowed )values(15154656,微观经济学,5,李小刚,北京大学出版社,2000-10-03,2001-11-15,1);insert into system_books(bookid ,bookname, book
15、styleno,bookauthor,bookpub, bookpubdate,bookindate, isborrowed )values(5658,影视文学,4,苏庆东,北京大学出版社,1999-02-28,2000-01-21,1);insert into system_books(bookid ,bookname, bookstyleno,bookauthor,bookpub, bookpubdate,bookindate, isborrowed )values(565800020,探索宇宙奥秘,2,苏庆东,北京大学出版社,1999-02-28,2000-01-21,1);3.2.3将
16、已有图书证的读者加入system_readers表中*/insert into system_readers(readerid,readername,readersex,readertype,regdate)values(X05620207,陈远鹏,男,学生,2005-9-23 14:23:56)insert into system_readers(readerid,readername,readersex,readertype,regdate)values(X05620206,陈特,男,学生,2005-09-30 13:24:54.623)insert into system_readers
17、(readerid,readername,readersex,readertype,regdate)values(X05620204,赵铭静,女,学生,2005-09-27 11:24:54.123)insert into system_readers(readerid,readername,readersex,readertype,regdate)values(X05620202,潘虹,女,学生,2005-09-30 13:24:54.473)insert into system_readers(readerid,readername,readersex,readertype,regdate
18、)values(008415,蒋伟,男,教师,2004-04-30 09:24:54.478)insert into system_readers(readerid,readername,readersex,readertype,regdate)values(001456,李叶风,女,教师,2004-04-30 09:24:54.478)3.2.4添加已借书读者的记录,同时将在已借出的借阅标记置0*/insert into borrow_record(bookid,readerid,borrowdate)values(00125415152,X05620202,2007-09-27 11:24
19、:54.123)update system_booksset isborrowed=0where bookid=00125415152insert into borrow_record(bookid,readerid,borrowdate)values(00125415153,X05620206,2007-12-27 08:26:51.452)update system_booksset isborrowed=0where bookid=00125415153 and isborrowed=1insert into borrow_record(bookid,readerid,borrowdat
20、e)values(5455515,X05620207,2007-12-27 08:26:51.452)update system_booksset isborrowed=0where bookid=5455515 and isborrowed=1insert into borrow_record(bookid,readerid,borrowdate)values(015115,X05620204,2007-10-21 12:11:51.452)update system_booksset isborrowed=0where bookid=015115 and isborrowed=1inser
21、t into borrow_record(bookid,readerid,borrowdate)values(15154656,001456,2007-12-28 14:11:51.312)update system_booksset isborrowed=0where bookid=15154656 and isborrowed=1insert into borrow_record(bookid,readerid,borrowdate)values(565800020,008415,2007-08-28 15:11:31.512)update system_booksset isborrow
22、ed=0where bookid=565800020 and isborrowed=1四、实验数据示例:测试阶段4.1单表查询4.1.1表book_style中查询演示:图-1 表book_style中内容4.1.2表system_books中查询演示:图-2 表system_books中内容4.1.3将已有图书证的读者加入system_readers表中结果查询:图-3 表system_readers中内容4.1.4借书纪录表borrow_record结果查询:图-4 表borrow_record中内容4.2还书操作4.2.1现在对某一读者进行还书操作:1首先还书要在还书纪录中添加一条还书纪
23、录2其次删除相应书本的借阅纪录3最后在书库中标记该本书为1,表示归还了未借,可供其他读者借阅说明:学号为X05620207 姓名为陈远鹏 借阅的565800020书籍编号进行归还。SQL语言:insert into return_record(bookid,readerid,returndate)select bookid,readerid,getdate()from borrow_recordwhere bookid=565800020(所影响的行数为 1 行)delete from borrow_recordwhere bookid=565800020(所影响的行数为 1 行)update
24、 system_booksset isborrowed=1where bookid=565800020(所影响的行数为 1 行)三个表的结果如图:图-5 增加了565800020纪录图-6 565800020这本书在借书纪录里没有了图-7 标记设为了1说明:这本书重新回到未被借出标记为1(注,相同的书其编号是不同的)其结果为还书成功,相应的各表都有变化,对于罚款单通过借阅记录表borrow_record中更新。4.3借书操作4.3.1查询未被借出的书本:图-84.3.2查询已被借出的书本:图-94.3.3申请借书证:SQL语言:Insert into system_readers(reader
25、id,readername,readersex,readertype,regdate)values(X05620211,小华,男,学生,getdate()图-10说明:查询相应的纪录增加了小华这样一个读者的借书证纪录:4.3.4注销借书证:说明:1在注销之前执行所有的还书过程,就是上面写到的所述SQL语句,然后执行delete from system_readers where readerid= X05620211,2小华借书证纪录就被删除了,同时要删除和小华归还纪录的内容delete from return_record where readerid= X05620211,4.3.5查询所
26、有书所对应的类别:图-114.4书籍状态4.4.1查询所有工技术类的书:图-124.4.2查询清华大学出版社出版的书:图-134.5读者状态4.5.1查询什么人借了什么书:图-144.5.2查询潘虹借了什么书:图-15五、课程设计心得在大二的下学期我们学校了数据库这门课,对这门课的第一印象就是书本不厚,感觉学起来应该会很轻松。但随着这门课学习的深入,我发现这门课并不是那么容易的,涉及的范围比较广,而且有的时候,使用不同的方法解题往往会发现,原来那样做这么简单,所以,针对不同的情况要具体分析,千万不要生搬硬套,这样虽然可能也会达到最终的效果,但是会使解题过程太过复杂,往往会造成事倍功半的后果。同样,通过这次数据库课程设计,我也是受益匪浅。从搜集资料到完成,差不多花了两个星期的时间,其实这个图书库存管理系统不是很难,但是,里面涉及到了一些上课没有涉及到的,后来去查找资料,才发现原来我们上课时学习的只是一些皮毛,还有许多需要我们掌握的东西我们根本不知道。同时也发现有很多已经学过的东西我们没有理解到位,不能灵活的运用于实际,不能很好的解决问题,而这一点恰恰需要我们不断的大量的实践,通过不断的学习,不断的发现问题,思考问题,进而解决问题。这是一个温故知新的过程。
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1