cod-asignment on database for college library
TRANSCRIPT
-
8/4/2019 COD-Asignment on Database for College Library
1/32
London School of Commerce
MSC IT
A Database for a College Library
Md Fahim Uddin
Student ID: L0263MHMH1110
This Assignment submitted in partial fulfilment of the requirement for the QP Semesterof the MSC IT, London School of Commerce 2011
-
8/4/2019 COD-Asignment on Database for College Library
2/32
2Concept of Database, MSC IT
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
-
8/4/2019 COD-Asignment on Database for College Library
3/32
3Concept of Database, MSC IT
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
-
8/4/2019 COD-Asignment on Database for College Library
4/32
4Concept of Database, MSC IT
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.
-
8/4/2019 COD-Asignment on Database for College Library
5/32
5Concept of Database, MSC IT
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
1.3 How does it Work?
Usually the library database system is developed to bring more flexibility while issuing or
receiving book. A library database system usually contain of the following feature:
Administrative area: The librarian can add / modify / delete books like book from this
area. It also allows librarian to perform several task related with member such as
add/modify members information as well as suspend or activate a members account.
Member area: This area allows member to search/view a book, reserve a book.
-
8/4/2019 COD-Asignment on Database for College Library
6/32
6Concept of Database, MSC IT
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.
1.4 Rationale of the project
With the changing of technology we are being familiar with new technologies and expecting
more work in less time. Any electronic system is developed to perform a task more accurately in
less time. Todays library user also expects speed and accuracy while they search for a book. A
database system allows the user to search for their desired book and show the result in a very
short time.
The rationale study, which is finding fundamental reasons behind the database system,
Easy to track a book
Easy to rearrange them
Easy to issue/collect book
Less probability of losing.
1.5 Barriers of database System
This is very natural for every system to have some barriers to be implemented. And this fact is
also true for library database system. There are some possible barriers for library database
system, such as:
Shortage of available fund
Fear that the technology could be very expensive
Lack of qualified library staff to support the new database system
Lack of Support from management: Some it is very difficult to convincing the
management that the user of library will be benefited by the new system. And also it willhelp the staff to do support more members in short time.
Data conversion: It is very difficult to transfer all paper based data into database.
-
8/4/2019 COD-Asignment on Database for College Library
7/32
7Concept of Database, MSC IT
1.6 Systems Development Phases
There are some steps should be followed to develop any database application called System
Development Life Cycle (SDLC). The SDLC has several steps which are given below:
Project planning, feasibility study: Determines the goal of the system and establish its
executing path. In this phase the developer/analyst often need to Interview Companys
individual to collect desired information.
Systems analysis, requirements definition: This process is to understand actually what user is
looking for and what they expect from the proposed system. In the other word, this phase of
SDLC refines project goals into defined functions and operations.
Systems design: To describe project features and functions in more details, including screen
layouts, process diagrams, business rules and procedures.
Implementation: This phase is kingdom of programmer/developer. The real program code is
written here.
Integration and testing: In which all modules of system are tested as a group. The purpose of
integration and testing is to ensure that all functions are performing perfectly and they are
reliable.
Maintenance: This is the most important phase of all, changes, correction, additions, and
move to one platform to another takes place in this phase. And this is the ever last phase of
SDLC
-
8/4/2019 COD-Asignment on Database for College Library
8/32
8Concept of Database, MSC IT
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
2.1.2 Components of ERD
Entity: The entity could be a person, object, place or event for what/which data is
collected, e.g. Student, Lecturer, Book.
Relationship: The interaction between entities in a database, like relation between Student
and Book.
Cardinality: It defines the type of relationship between entities in terms of number of
occurring. The three common cardinalities are:
1. One-to-One
Example: Relation Borrow and Book (If any member fails to return book in the
given time so fine will be applied for that particular BorrowID)
2. One-to-Many
Example: Relation between Mother and Children (A mother could have more
many children)
3. Many-to-Many
Example: Relation between book and library member (A book could be borrowed
by more than one student, and a student could borrow many books)
-
8/4/2019 COD-Asignment on Database for College Library
9/32
9Concept of Database, MSC IT
2.1.3 History of ERD
ERD was first introduced by Charles Bachman. Bachman Diagram described data structure.
And he recognised the need to data model at a higher level of abstraction.
entity stands for a specific obeject. The term class of entity mean a group of entities those a
similar..below
ERD was popularised by Dr. Pin-Shan (Peter) Chen in 1976, but he worked on the previous work
of his colleagues, one of whom was Charles Bachman.
2.2 Unified Modeling Language (UML)
To design the ERD for this system (Database for College Library) I will use Unified Modeling
Language (UML).
2.2.1 What is Unified Modelling Language (UML)
It is a graphical language to visualizing, specifying, constructing and documenting the artefact
software. UML is a standardised general purpose language in the software industry. A software
engineer could visualize the blueprint of the system using the elements of UML, such as:
Activities
Actors
Business Processes
Database Schemas
Logical Components
Programming Language Statements
2.2.2 History UML
In 1996 the UML Partners was organized to specifying and propose it to the ONG REF. And thedraft of UML 1.0 was proposed to the OMG in January 1997 and adopted by the OMG in
November 1997. Over the last few years some modification has took place to the language, as a
result UML 2.0 came out with the major revision to the UML.
-
8/4/2019 COD-Asignment on Database for College Library
10/32
10Concept of Database, MSC IT
2.3 Database (MySql)I would like to use MySql 5.1 as the Database for the College Library System as it one of the
powerful and rapid growing Relational Database System in the industry. Also it is worlds most
popular open source database.
In the mid-1990s, MYSQL was a major promoter of the network computer, forming subsidiary
Network Computer, Inc. to define the specifications for the platform. Although the network
computer did not take off, the principles it embodied are widely used in today's thin client
architectures and are ever increasing. MYSQL has been installed in system for the further project
development phase. (Lakshman ,2003)
2.3.1 Why MySql
The MySql database has become worlds most popular open source database because of:
1. MySql has got high performance, reliability and easy to use.
2. It is very suitable for the application built on the LAMP (Linux, Apache, MySql, PHP).
3. Many of the worlds most popular companies like Facebook, Adobe, Alcatel are using
MySql.
4. MySql runs on more than 20 operating systems including Linux, Windows, Mac OS,
Solaris and IBM.
5. Its free of cost.
-
8/4/2019 COD-Asignment on Database for College Library
11/32
11Concept of Database, MSC IT
2.4 ERD of the Database of College Library
-
8/4/2019 COD-Asignment on Database for College Library
12/32
12Concept of Database, MSC IT
2.5 Data Dictionary
Table: address
Field Type Null Default Comments
addressId int(11) No
flat varchar(5) Yes NULL
house varchar(25) Yes NULL
road varchar(25) Yes NULL
city varchar(25) Yes NULL
county varchar(25) Yes NULL
postcode varchar(12) No
country varchar(25) No
Table: author
Field Type Nul
l
Default Comments
authorId int(11) No
name varchar(50) No
aboutAuthor varchar(255) Yes NULL
Table: book
Field Type Nul
l
Default Comments
bookId int(11) No
title varchar(100) No
isbn varchar(13) No
-
8/4/2019 COD-Asignment on Database for College Library
13/32
13Concept of Database, MSC IT
language varchar(25) No
numOfPage int(4) No
binding varchar(15) Yes NULL
size varchar(25) Yes NULL
version varchar(25) Yes NULL
qtyAvailable int(3) No
Table: book_author
Field Type Nul
l
Default Comments
bookId int(11) No
authorId int(11) No
Table: book_publisher
Field Type Nul
l
Default Comments
publisherId int(11) No
bookId int(11) No
Table: book_qty
Field Type Nul
l
Default Comments
qtyId int(11) No
bookId int(11) No
action varchar(10) No added/removed
-
8/4/2019 COD-Asignment on Database for College Library
14/32
14Concept of Database, MSC IT
qty int(3) No
date date No
Table: borrow
Field Type Nul
l
Default Comments
borrowId int(11) No
memberId int(11) No
bookId int(11) No
borrowDate date No
expReturndate date No
returnDate date Yes NULL
librarianId int(11) No
Table: fine
Field Type Nul
l
Default Comments
fineId int(11) No
borrowId int(11) No
amount decimal(10,2) No
-
8/4/2019 COD-Asignment on Database for College Library
15/32
15Concept of Database, MSC IT
Table: librarian
Field Type Nul
l
Default Comments
librarianId int(11) No
userName varchar(50) No
password varchar(15) No
Table: member
Field Type Nul
l
Default Comments
memberId int(11) No
name varchar(50) No
email varchar(50) No
password varchar(15) No
addressId int(11) No
sex varchar(6) Yes NULL
nationality varchar(30) Yes NULL
dob date No
oinDate date No
memberType varchar(8) No student/lecturer
-
8/4/2019 COD-Asignment on Database for College Library
16/32
16Concept of Database, MSC IT
Table: member_phone_number
Field Type Nul
l
Default Comments
phoneNumber varchar(25) No
memberId int(11) No
priority int(1) No
Table: member_proof_of_id
Field Type Nul
l
Default Comments
IdType varchar(12) No proof of id/proof of address
memberId int(11) No
scannedCopy varchar(25) No
Table: payment
Field Type Nul
l
Default Comments
transactionId varchar(20) No
fineId int(11) No
amount decimal(10,2) No
transactionDate date No
transactionTime time No
librarianId int(11) Yes NULL
-
8/4/2019 COD-Asignment on Database for College Library
17/32
17Concept of Database, MSC IT
Table: publisher
Field Type Nul
l
Default Comments
publisherId int(11) No
bookId int(11) No
aboutPublisher varchar(255) Yes NULL
Table: reservation
Field Type Null Default Comments
reserveId int(11) No
memberId int(11) No
bookId int(11) No
bookAvailDate date No possible book available date
reserveExpDate date No reserve expiration date :: may be 3 days
from book available date
-
8/4/2019 COD-Asignment on Database for College Library
18/32
18Concept of Database, MSC IT
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 databaseconsumes.
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 1 st,
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 PK
BorrowDate
ExpectedReturnDate
ReturnDate
MemberName
MemberDOB
MemberAddress
BookID PK
BookTitle
BookISBN
-
8/4/2019 COD-Asignment on Database for College Library
19/32
19Concept of Database, MSC IT
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.
-
8/4/2019 COD-Asignment on Database for College Library
20/32
20Concept of Database, MSC IT
2.7 Create Database
CREATE DATABASE library_management
2.7.1 Create TablesCREATE TABLE address (
addressId int(11) NOT NULL auto_increment,
flat varchar(5) default NULL,
house varchar(25) default NULL,
road varchar(25) default NULL,
city varchar(25) default NULL,
county varchar(25) default NULL,
postcode varchar(12) NOT NULL,
country varchar(25) NOT NULL,
PRIMARY KEY (addressId),
UNIQUE KEY postcode (postcode)
) ENGINE=InnoDB;
CREATE TABLE author (
authorId int(11) NOT NULL auto_increment,
name varchar(50) NOT NULL,
aboutAuthor varchar(255) default NULL,
PRIMARY KEY (authorId)
) ENGINE=InnoDB;
-
8/4/2019 COD-Asignment on Database for College Library
21/32
21Concept of Database, MSC IT
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;
-
8/4/2019 COD-Asignment on Database for College Library
22/32
22Concept of Database, MSC IT
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;
-
8/4/2019 COD-Asignment on Database for College Library
23/32
23Concept of Database, MSC IT
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;
-
8/4/2019 COD-Asignment on Database for College Library
24/32
24Concept of Database, MSC IT
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),
-
8/4/2019 COD-Asignment on Database for College Library
25/32
25Concept of Database, MSC IT
UNIQUE KEY email (email),
KEY addressId (addressId)
) ENGINE=InnoDB;
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;
-
8/4/2019 COD-Asignment on Database for College Library
26/32
26Concept of Database, MSC IT
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;
-
8/4/2019 COD-Asignment on Database for College Library
27/32
27Concept of Database, MSC IT
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;
-
8/4/2019 COD-Asignment on Database for College Library
28/32
28Concept of Database, MSC IT
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) REFERENCESlibrarian (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
-
8/4/2019 COD-Asignment on Database for College Library
29/32
29Concept of Database, MSC IT
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) REFERENCESlibrarian (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;
-
8/4/2019 COD-Asignment on Database for College Library
30/32
30Concept of Database, MSC IT
2.8 SQL Statement for Required Functions
2.7.1 Student Join the Library
INSERT INTO member (Fahim Uddin, [email protected], password, address_id, male,
Bangladeshi, 1988-01-25, 2011-02-15, Student);
Note: The memberId of member table will be generated automatically and the address_id in the
above query is the ID of address table.
2.7.2 Lecturer Join the Library
INSERT INTO member (Fahim Uddin, [email protected], password, address_id, male,
Bangladeshi, 1988-01-25, 2011-02-15, Lecturer);
2.7.3 Member Leave the Library
DELETE FROM member WHERE memberId=1;
Note: The memberId will be provided by the user, so system will delete the member belongs to
that id.
2.7.4 Member Borrow Book
INSERT INTO borrow (member_id, book_id, 2011-02-15, 2011-02-25, , librarian_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 borrowing the book and the book_id is the id
of which is taken by member.
-
8/4/2019 COD-Asignment on Database for College Library
31/32
31Concept of Database, MSC IT
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
-
8/4/2019 COD-Asignment on Database for College Library
32/32
32Concept of Database, MSC IT
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