COD-Asignment On Database For College Library
COD-Asignment On Database For College Library
MSC IT
This Assignment submitted in partial fulfilment of the requirement for the QP Semester of the MSC IT, London School of Commerce 2011
Contents
Abstract ......................................................................................................................................................... 4 Chapter 1....................................................................................................................................................... 5 Introduction .............................................................................................................................................. 5 1.1 Background & Context .................................................................................................................... 5 1.2 Aim .................................................................................................................................................. 5 1.3 How does it Work? .......................................................................................................................... 5 1.4 Rationale of the project .................................................................................................................. 6 1.5 Barriers of database System ........................................................................................................... 6 1.6 Systems Development Phases ........................................................................................................ 7 Chapter 2....................................................................................................................................................... 8 2.1 Entity Relationship Diagram (ERD) ...................................................................................................... 8 2.1.1 What is Entity Relationship Diagram (ERD).................................................................................. 8 2.1.2 Components of ERD ..................................................................................................................... 8 2.1.3 History of ERD .............................................................................................................................. 9 2.2 Unified Modeling Language (UML) ..................................................................................................... 9 2.2.1 What is Unified Modelling Language (UML) ................................................................................ 9 2.2.2 History UML ................................................................................................................................. 9 2.3 Database (MySql) .............................................................................................................................. 10 2.3.1 Why MySql ................................................................................................................................. 10 2.4 ERD of the Database of College Library ............................................................................................ 11 2.5 Data Dictionary ................................................................................................................................. 12 2.6 Normalization.................................................................................................................................... 18 2.6.1 The Normal Forms...................................................................................................................... 18 2.6.2 The 1st Normal Form .................................................................................................................. 18 2.6.2 The 2nd Normal Form.................................................................................................................. 19 2.6.3 The 3rd Normal Form .................................................................................................................. 19 2.7 Create Database ................................................................................................................................ 20 2.7 Create Database ................................................................................................................................ 20 CREATE DATABASE library_management .................................................................................... 20 2.7.1 Create Tables ............................................................................................................................. 20 2.7.1 Relationship ............................................................................................................................... 27
2.8 SQL Statement for Required Functions............................................................................................. 30 2.7.1 Student Join the Library ............................................................................................................. 30 2.7.2 Lecturer Join the Library ............................................................................................................ 30 2.7.3 Member Leave the Library ......................................................................................................... 30 2.7.4 Member Borrow Book ............................................................................................................... 30 2.7.5 Member Return Book ................................................................................................................ 31 2.7.6 Member Check Book: is Available or not ................................................................................... 31 2.7.8 Librarian Search for Book those are Overdue ............................................................................ 31 2.8 Conclusion ......................................................................................................................................... 32 2.9 Reference .............................................................................................................................................. 32
Abstract
One of the technologies that most people have become familiar with either at work or while studying in School/College/University is Database. The word Database in an extremely technical term, however because of essentiality of information technology in our daily life, the Database has become one of the important part of our life. A Database for a College Library is an enterprise resource planning system for a library, used to track books owned, person who have borrowed. It is a very useful system for any library to serve the customer better and mange books. I have designed this Database to: Store Books information Student/Lecturer Information Receipt and issuance of books borrowed by the members Collect fine from those members who are failed to return books in the given time.
Chapter 1
Introduction
1.1 Background & Context Before invention of computer libraries were used to use card catalogue to index their holdings. But later, when computer becomes available card catalogue system replaced by automated system which called library automation. Automation of the library saves labour and time in resort the catalogue and keeping it up-to-date. As a result of high traffic in libraries it is very difficult to track the books while it is required by reader/member. So the demand of database system is increasing day by day. Therefore a database is very essential for library to store the information of Book, distributing them on demand and collect them in proper time. A good database helps a library to trail towards its goal and make sure the members satisfaction.
1.2 Aim
The main aim of this proposal is to develop a database for college library. The aims of the database system are as below: To develop the service quality To make the information available to librarian and member of library To make library work more easier including borrow and return process
Staff Area: Library staff could issue a book to any member or collect book from member in this area. This area also provides facility to collect fine from member if the member fails to return the borrowed book in the given time.
Chapter 2
2.1 Entity Relationship Diagram (ERD)
2.1.1 What is Entity Relationship Diagram (ERD)
The ER Diagram is also known as E-R Diagram and entity-relationship model. ERD is a high level data model that graphically explains the interrelationships among the entities of a database. ERD often use some special symbol to represent the information like: Box used to represent entity Diamond used to represent relationship Oval used to represent attributes
10
11
12
varchar(25) Yes varchar(25) Yes varchar(25) Yes varchar(25) Yes varchar(12) No varchar(25) No
Table: author Field Type Nul Default Comments l authorId name aboutAuthor int(11) varchar(50) No No
Table: book Field Type Nul Default Comments l bookId title isbn int(11) No
varchar(100) No varchar(13) No
13
Table: book_author Field Type Nul Default Comments l bookId authorId int(11) int(11) No No
Table: book_publisher Field Type Nul Default Comments l publisherId bookId int(11) int(11) No No
Table: book_qty Field Type Nul Default Comments l qtyId bookId action int(11) int(11) varchar(10) No No No added/removed
14
qty date
int(3) date
No No
Table: borrow Field Type Nul Default Comments l borrowId memberId bookId borrowDate expReturndate returnDate librarianId int(11) int(11) int(11) date date date int(11) No No No No No Yes NULL No
Table: fine Field Type Nul Default Comments l fineId borrowId amount int(11) int(11) No No
decimal(10,2) No
15
Table: librarian Field Type Nul Default Comments l librarianId userName password int(11) varchar(50) varchar(15) No No No
Table: member Field Type Nul Default Comments l memberId name email password addressId sex nationality dob joinDate memberType int(11) varchar(50) varchar(50) varchar(15) int(11) varchar(6) varchar(30) date date varchar(8) No No No No No Yes NULL Yes NULL No No No student/lecturer
16
Table: member_phone_number Field Type Nul Default Comments l phoneNumber memberId priority varchar(25) int(11) int(1) No No No
Table: member_proof_of_id Field Type Nul Default Comments l IdType memberId scannedCopy varchar(12) int(11) varchar(25) No No No proof of id/proof of address
Table: payment Field Type Nul Default Comments l transactionId fineId amount varchar(20) int(11) No No
17
Table: publisher Field Type Nul Default Comments l publisherId bookId aboutPublisher int(11) int(11) No No
Table: reservation Field reserveId memberId bookId Type int(11) int(11) int(11) Null No No No No No possible book available date reserve expiration date :: may be 3 days from book available date Default Comments
18
2.6 Normalization
Normalization is the process to organize data in the database efficiently. There are two main objective of normalization. 1) Minimizing the redundancy of data and (2) organizing the data dependency. Both of these are worthy goals as to reduce the amount of space a database consumes. 2.6.1 The Normal Forms The database community has developed a series of method called Normal Forms to ensure that the database is normalized perfectly. The number of normal forms is 5. Most application uses 1st, 2nd and 3rd normal forms. The 4th normal form used occasionally, but the use of 5th normal form is rear. about.com. 2.6.2 The 1st Normal Form Remove repeating group of data from individual table. Create separate table for the same group of data Identify each set of related data with a primary key. Example
BorrowID BorrowDate ExpectedReturnDate ReturnDate MemberName MemberDOB MemberAddress BookID BookTitle BookISBN
PK
PK
19
2.6.2 The 2nd Normal Form Ensure that all data is depended on primary key fully. For example if there is any composite key so the 2nd NF ensure that all data depends on the both part of primary key not partially. Example: Based on 1st, 2 tables will be created for Borrow and Book
2.6.3 The 3rd Normal Form Meets all the requirements of 2nd NF and remove all non key dependency. Example: in borrow table member information is non key dependent. So another table will be created called member and will be related with borrow.
20
21
CREATE TABLE book ( bookId int(11) NOT NULL auto_increment, title varchar(100) NOT NULL, isbn varchar(13) NOT NULL, language varchar(25) NOT NULL, numOfPage int(4) NOT NULL, binding varchar(15) default NULL, size varchar(25) default NULL, version varchar(25) default NULL, qtyAvailable int(3) NOT NULL, PRIMARY KEY (bookId) ) ENGINE=InnoDB;
CREATE TABLE book_author ( bookId int(11) NOT NULL, authorId int(11) NOT NULL, PRIMARY KEY (bookId,authorId), KEY authorId (authorId) ) ENGINE=InnoDB;
22
CREATE TABLE book_publisher ( publisherId int(11) NOT NULL, bookId int(11) NOT NULL, PRIMARY KEY (publisherId,bookId), KEY bookId (bookId) ) ENGINE=InnoDB;
CREATE TABLE book_qty ( qtyId int(11) NOT NULL auto_increment, bookId int(11) NOT NULL, action varchar(10) NOT NULL COMMENT 'added/removed', qty int(3) NOT NULL, date date NOT NULL, PRIMARY KEY (qtyId), KEY bookId (bookId) ) ENGINE=InnoDB;
23
CREATE TABLE borrow ( borrowId int(11) NOT NULL auto_increment, memberId int(11) NOT NULL, bookId int(11) NOT NULL, borrowDate date NOT NULL, expReturndate date NOT NULL, returnDate date NOT NULL, librarianId int(11) NOT NULL, PRIMARY KEY (borrowId), KEY memberId (memberId), KEY bookId (bookId), KEY librarianId (librarianId) ) ENGINE=InnoDB;
CREATE TABLE fine ( fineId int(11) NOT NULL auto_increment, borrowId int(11) NOT NULL, amount decimal(10,2) NOT NULL, PRIMARY KEY (fineId), KEY borrowId (borrowId) ) ENGINE=InnoDB;
24
CREATE TABLE librarian ( librarianId int(11) NOT NULL auto_increment, userName varchar(50) NOT NULL, password varchar(15) NOT NULL, PRIMARY KEY (librarianId), UNIQUE KEY userName (userName) ) ENGINE=InnoDB;
CREATE TABLE member ( memberId int(11) NOT NULL, name varchar(50) NOT NULL, email varchar(50) NOT NULL, password varchar(15) NOT NULL, addressId int(11) NOT NULL, sex varchar(6) default NULL, nationality varchar(30) default NULL, dob date NOT NULL, joinDate date NOT NULL, memberType varchar(8) NOT NULL COMMENT 'student/lecturer', PRIMARY KEY (memberId),
25
CREATE TABLE member_phone_number ( phoneNumber varchar(25) NOT NULL, memberId int(11) NOT NULL, priority int(1) NOT NULL, PRIMARY KEY (phoneNumber,memberId), KEY memberId (memberId) ) ENGINE=InnoDB;
CREATE TABLE member_proof_of_id ( IdType varchar(12) NOT NULL COMMENT 'proof of id/proof of address', memberId int(11) NOT NULL, scannedCopy varchar(25) NOT NULL, PRIMARY KEY (IdType,memberId), KEY memberId (memberId) ) ENGINE=InnoDB;
26
CREATE TABLE payment ( transactionId varchar(20) NOT NULL, fineId int(11) NOT NULL, amount decimal(10,2) NOT NULL, transactionDate date NOT NULL, transactionTime time NOT NULL, librarianId int(11) default NULL, PRIMARY KEY (transactionId), KEY librarianId (librarianId), KEY fineId (fineId) ) ENGINE=InnoDB;
CREATE TABLE publisher ( publisherId int(11) NOT NULL, bookId int(11) NOT NULL, aboutPublisher varchar(255) default NULL, PRIMARY KEY (publisherId), KEY bookId (bookId) ) ENGINE=InnoDB;
27
CREATE TABLE reservation ( reserveId int(11) NOT NULL auto_increment, memberId int(11) NOT NULL, bookId int(11) NOT NULL, bookAvailDate date NOT NULL COMMENT 'possible book available date', reserveExpDate date NOT NULL COMMENT 'reserve expiration date :: may be 3 days from book available date', PRIMARY KEY (reserveId), KEY memberId (memberId), KEY bookId (bookId) ) ENGINE=InnoDB;
2.7.1 Relationship Create many-to-many relationship between book and author via another table book_authro
ALTER TABLE book_author ADD CONSTRAINT book_author_ibfk_1 FOREIGN KEY (bookId) REFERENCES book (bookId) ON DELETE NO ACTION ON UPDATE CASCADE, ADD CONSTRAINT book_author_ibfk_2 FOREIGN KEY (authorId) REFERENCES author (authorId) ON DELETE NO ACTION ON UPDATE CASCADE;
28
Create many-to-many relationship between book and publisher via another table book_publisher: ALTER TABLE book_publisher ADD CONSTRAINT book_publisher_ibfk_1 FOREIGN KEY (publisherId) REFERENCES publisher (publisherId) ON DELETE NO ACTION ON UPDATE CASCADE, ADD CONSTRAINT book_publisher_ibfk_2 FOREIGN KEY (bookId) REFERENCES book (bookId) ON DELETE NO ACTION ON UPDATE CASCADE; ALTER TABLE publisher ADD CONSTRAINT publisher_ibfk_1 FOREIGN KEY (bookId) REFERENCES book (bookId) ON DELETE NO ACTION ON UPDATE CASCADE;
Create one-to-many relationship between book and book_qty ALTER TABLE book_qty ADD CONSTRAINT book_qty_ibfk_1 FOREIGN KEY (bookId) REFERENCES book (bookId) ON DELETE NO ACTION ON UPDATE CASCADE;
Create many-to-many relationship between book and member via intermediate table borrow, and relation between borrow and librarian as librarian entry borrow record: ALTER TABLE borrow ADD CONSTRAINT borrow_ibfk_3 FOREIGN KEY (librarianId) REFERENCES librarian (librarianId) ON DELETE NO ACTION ON UPDATE CASCADE, ADD CONSTRAINT borrow_ibfk_1 FOREIGN KEY (memberId) REFERENCES member (memberId) ON DELETE NO ACTION ON UPDATE CASCADE, ADD CONSTRAINT borrow_ibfk_2 FOREIGN KEY (bookId) REFERENCES book (bookId) ON DELETE NO ACTION ON UPDATE CASCADE;
One-to-one relationship between borrow and fine (if any fine) ALTER TABLE fine ADD CONSTRAINT fine_ibfk_1 FOREIGN KEY (borrowId) REFERENCES borrow (borrowId) ON DELETE NO ACTION ON UPDATE CASCADE;
One-to-one relationship between member address as many member can be live in one address ALTER TABLE member
29
ADD CONSTRAINT member_ibfk_1 FOREIGN KEY (addressId) REFERENCES address (addressId) ON DELETE NO ACTION ON UPDATE CASCADE; One-to-many relationship between member_phone_number and member as a member can have more than one number ALTER TABLE member_phone_number ADD CONSTRAINT member_phone_number_ibfk_1 FOREIGN KEY (memberId) REFERENCES member (memberId) ON DELETE NO ACTION ON UPDATE CASCADE; One-to-one relation between member_proof_of_id and member as a member must have two id (photo and proof of address) ALTER TABLE member_proof_of_id ADD CONSTRAINT member_proof_of_id_ibfk_1 FOREIGN KEY (memberId) REFERENCES member (memberId) ON DELETE NO ACTION ON UPDATE CASCADE; One-to-many relationship between fine and fine_payment as a payment could be paid by installment, and one-to-many relation between librarian and fine_payment as a librarian would collect all payment ALTER TABLE payment ADD CONSTRAINT payment_ibfk_2 FOREIGN KEY (librarianId) REFERENCES librarian (librarianId) ON DELETE NO ACTION ON UPDATE CASCADE, ADD CONSTRAINT payment_ibfk_1 FOREIGN KEY (fineId) REFERENCES fine (fineId) ON DELETE NO ACTION ON UPDATE CASCADE; Many-to-many relationship between book and member via reservation, because a member can book more than one book and a book also could be booked by many member ALTER TABLE reservation ADD CONSTRAINT reservation_ibfk_1 FOREIGN KEY (memberId) REFERENCES member (memberId) ON DELETE NO ACTION ON UPDATE CASCADE, ADD CONSTRAINT reservation_ibfk_2 FOREIGN KEY (bookId) REFERENCES book (bookId) ON DELETE NO ACTION ON UPDATE CASCADE;
30
31
2.7.5 Member Return Book UPDATE borrow SET returnDate=CURRENT_DATE WHERE memberId=member_id AND bookId=book_id; Update book table and set qtyAvailable=+1 for this book UPDATE book SET qtyAvailable= qtyAvailable+1 WHERE bookId=book_id; Note: The member_id is the id of member who is returning the book and the book_id is the id of which is return by the member. 2.7.6 Member Check Book: is Available or not Search by book Title: SELECT title FROM book WHERE qtyAvailable >0 AND title LIKE %user_given_parameter%; Search by ISBN: SELECT title FROM book WHERE qtyAvailable >0 AND isbn=
user_given_parameter; Search by Author: SELECT b.title FROM book AS b, book_author AS ba, author AS a WHERE b.qtyAvailable >0 AND a.name LIKE %user_given_parameter% AND b.ID=ba.bookId AND a.ID=ba.authorId; Search by Publisher: SELECT b.title FROM book AS b, book_publisher AS bp, publisher AS p WHERE b.qtyAvailable >0 AND p.name LIKE %user_given_parameter% AND b.ID= bp.bookId AND p.ID= bp.publisherId; 2.7.8 Librarian Search for Book those are Overdue SELECT b.title FROM book AS b, borrow AS br WHERE br.returnDate IS NULL AND br.expReturnDate <CURRENT_DATE
32
2.8 Conclusion
Finally based on this article I would like to say that the database is a very important part of a library. A database can help a library to use its each resource in a perfect way. A library management system can ensure proper resource management and customer satisfaction.
2.9 Reference
Page 4 of "Bachman, C. W. (1969) Data Structure Diagrams. DATA BASE 1(2): 4-10" Bulusu L. (2003) Oracle9i PL/SQLA Developer's Guide Publish by Apress 1st edition