MARCH 20, 2018
ASSIGNMENT
DBI202 – DATABASE SYSTEM OF LIBRARY
MANAGEMENT SYSTEM
STUDENT NAME: PHAM NGOC HOA | SE05740
STUDENT NAME: NGUYEN HAI NAM | SE05123
Teacher: nguyen quynh chi
DBI202
TABLE OF CONTENTS
I) INTRODUCE THE PROBLEM…………………………………………………………………………………………….
1) DESCRIBE THE PROBLEM……………………………………………………………………………………………………….
2) MANAGEMENT OBJECTIVES…………………………………………………………………………………………………..
II) ENTITY – RELATIONSHIP – ER…………………………………………………………………………………………
1) DIFINITION ENTITY – ATTRIBUTE…………………………………………………………………………………………..
2) SET-UP ENTITY – RELATIONSHIP…………………………………………………………………………………………….
III) DATA DICTIONARY………………………………………………………………………………………………………….
1) DEFINITION OF TABLES………………………………………………………………………………………………………….
1) SET-UP TRIGGER…………………………………………………………………………………………………………………….
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 1
DBI202
I) INTRODUCE THE PROBLEM
1) DESCRIBE THE PROBLEM
Nowadays, libraries need a system to manage books and readers of the library. Understanding that
problem, our team has designed a database that allows library management, specifically the following
objects: Readers. author , book , staff , library card , author , publisher,category.
Our team will manage the following:
Each book will have fields for information such as author, publisher, and genre.
Each employee will have basic information such as id, name, address.
Each reader will have basic information such as id , name , address , and importantly, a library
card to borrow and return books.
When borrowing/returning books, readers need to hand over the library card to the staff to
store information. That information includes library card code, name of staff lending/returning,
date of borrowing/returning,...
Each book can be borrowed many times and can borrow many books at a time.
Request:
Managers can know the author of any book, and the publisher of that book to advise readers.
Managers can see who borrowed the book and the employee who lent it
Managers can know the date readers borrow books, return books, and the expiration date of
books.
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 2
DBI202
II) ENTITY – RELATIONSHIP – ER
1) DIFINITION ENTITY – ATTRIBUTE
Base on the problem description and management objectives, we can present several entities and
attributes of the entity as follow:
- Staff (staffID, name, address, phone)
- Reserve_Return (code, reserverDate, dueDate, staffID, libraryCardID)
- Book(bookID, name, yearPublishing, authorID, categoryID, publisherID)
- Details (bookID, reserve_ReturnID, returnDate)
- Author (authorID, name, address)
- Category (categoryID, name)
- Publisher (publisherID, name,address,email)
- libraryCard (libraryCardID, openDate, expirationDate)
- Reader (readerID, name, phone, address)
- Reader_Card (readerID, libraryCardID)
2) SET-UP ENTITY – RELATIONSHIP
* Some symbols used in the model
Key / identifier attribute Attribute Attribute
Attribute description / description Attribute Attribute
Entity ENTITY
Weak entity WEAK ENTIRY
Relationship Relationship
Connectivity (force) = 1
Connectivity = N
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 3
DBI202
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 4
DBI202
WE HAVE A MODEL
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 5
DBI202
III) DATA DICTIONARY
Just for example on some tables (other table are similar, you have to define all the tables in your
database). Note: to run the query you have to define the table 1 first then go to the side tables much
1) DEFINITION OF TABLES
A. TABLE STAFF
Column Name Data Type Default Check Key/ Index/ Constraint
staffID Int PK, Not null
name Nvarchar(30) Not null
address Nvarchar(30) Not null
Phone Varchar(10) Begin 0 and Unique
10 digit
Code:
--create table Staff
CREATE TABLE Staff (
staffID int PRIMARY KEY not null,
name nvarchar(30) not null,
address nvarchar(20) not null,
phone varchar(10) UNIQUE CHECK(phone LIKE '0[0-9][0-9][0-9][0-9][0-9][0-9][0-9]
[0-9][0-9]') not null) --so dien thoai phai bat dau tu 0 va co 10 chu so
)
Result:
B. TABLE AUTHOR
Key/ Index/ Constraint
Column Name Data Type Default Check
authorID Int PK, Not null
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 6
DBI202
Key/ Index/ Constraint
Column Name Data Type Default Check
name Nvarchar(30) Not null
address Nvarchar(20) Not null
Code:
--create table author
CREATE TABLE Author (
authorID int PRIMARY KEY not null,
name nvarchar(30) not null,
address nvarchar(20) not null)
Result:
C. TABLE CATEGORY
Column Name Data Type Default Check Key/ Index/ Constraint
categoryID int Primary key,not null
name Nvarchar(30) Not null
Code:
--create Category
CREATE TABLE Category (
categoryID int PRIMARY KEY not null,
name nvarchar(30) not null)
Result:
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 7
DBI202
D. TABLE PUBLISHER
Column Name Data Type Default Check Key/ Index/ Constraint
publisherID Int PK, Not null
name Nvarchar(30) Not null
address Nvarchar(20) Not null
email Varchar(255) CONTAIN @ Unique
AND .
Code:
CREATE TABLE Publisher (
publisherID int PRIMARY KEY not null,
name nvarchar(30) not null,
address nvarchar(20) not null,
email varchar(255) UNIQUE CHECK(email LIKE '%@%.%') null)
Result:
E. TABLE READER
Column Name Data Type Default Check Key/ Index/ Constraint
readerID Int PK, Not null
name Nvarchar(30) Not null
address Nvarchar(20) Not null
Phone Varchar(10) Begin 0 and Unique
10 digit
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 8
DBI202
Code:
CREATE TABLE Reader (
readerID int PRIMARY KEY not null,
name nvarchar(30) not null,
address nvarchar(20) not null,
phone varchar(10) UNIQUE CHECK(phone LIKE '0[0-9][0-9][0-9][0-9][0-9][0-9][0-9]
[0-9][0-9]') not null)
Result:
F. TABLE LIBRARYCARD
Column Name Data Type Default Check Key/ Index/ Constraint
libraryCardID Int Identity(1,1) PK, Not null
openDate Date Not null
expirationDate Date openDate < Not null
expirationDate
Code:
CREATE TABLE libraryCard (
libraryCardID INT IDENTITY(1,1) PRIMARY KEY not null,
openDate DATE not null,
expirationDate DATE NOT null)
ALTER TABLE dbo.libraryCard
ADD CONSTRAINT checkDate CHECK(openDate<expirationDate)
Result:
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 9
DBI202
G. TABLE READER_CARD
Column Name Data Type Default Check Key/ Index/ Constraint
libraryCardID Int PK, Not null,FK, fk1
readerID Int Not null,FK, fk2
Code:
CREATE TABLE Reader_Card (
libraryCardID int not null,
readerID int not null,
constraint fk1 FOREIGN KEY(libraryCardID) REFERENCES libraryCard(libraryCardID)
ON UPDATE CASCADE,
constraint fk2 FOREIGN KEY(readerID) REFERENCES Reader(readerID)
ON UPDATE CASCADE)
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 10
DBI202
Result:
H. TABLE BOOK
Column Name Data Type Default Check Key/ Index/ Constraint
bookID Int PK, Not null
name Nvarchar(30) Not null
yearPublishin Int yearPublishing null
g < this Day
authorID Int fk_Books_Author
categoryID Int fk_Books_Category
publisherID Int fk_Books_Publisher
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 11
DBI202
Code:
CREATE TABLE Book (
bookID int PRIMARY KEY not null,
name nvarchar(30) not null,
yearPublishing int NULL CHECK(yearPublishing<YEAR(getDate())) , --Ngay xuat ban <
ngay hien tai
authorID int ,
categoryID int ,
publisherID int ,
constraint fk_Books_Author FOREIGN KEY(authorID) REFERENCES Author(authorID)
ON DELETE SET NULL
ON UPDATE CASCADE,
constraint fk_Books_Category FOREIGN KEY(categoryID) REFERENCES
Category(categoryID)
ON DELETE SET NULL
ON UPDATE CASCADE,
constraint fk_Books_Publisher FOREIGN KEY(publisherID) REFERENCES
Publisher(publisherID)
ON DELETE SET NULL
ON UPDATE CASCADE)
Result:
I. TABLE RESERVE_RETURN
Column Name Data Type Default Check Key/ Index/ Constraint
code Int IDENTITY(1, PK, Not null
1)
reserveDate Date Not null
dueDate Date reserveDate<dueDate Not null
staffID Int fk_Re_Staff
libraryCardID Int fk_Re_libraryCard
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 12
DBI202
Code:
CREATE TABLE Reserve_Return (
code int IDENTITY(1,1) PRIMARY KEY not null,
reserveDate DATE not null,
dueDate DATE not null,
staffID int ,
libraryCardID int,
constraint fk_Re_Staff FOREIGN KEY(staffID) REFERENCES Staff(staffID)
ON DELETE SET NULL
ON UPDATE CASCADE,
constraint fk_Re_libraryCard FOREIGN KEY(libraryCardID) REFERENCES
libraryCard(libraryCardID)
ON DELETE SET NULL
ON UPDATE CASCADE)
ALTER TABLE dbo.Reserve_Return
ADD CONSTRAINT checkDate1 CHECK(reserveDate<dueDate) -- Ngay tra sach < Ngay het
han muon
Result:
J. TABLE DETAILS
Column Name Data Type Default Check Key/ Index/ Constraint
bookID Int pk_Details, Not null,
fk_Details_Staff
Reserver_ReturnID Int pk_Details,Not null,
fk_Details_libraryCard
ReturnDate Date Null,
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 13
DBI202
Code:
CREATE TABLE Details (
bookID int not null,
reserve_ReturnID int not null,
returnDate DATE null,
constraint pk_Details PRIMARY KEY (bookID, reserve_ReturnID),
constraint fk_Details_Staff FOREIGN KEY(bookID) REFERENCES Book(bookID),
constraint fk_Details_libraryCard FOREIGN KEY(reserve_ReturnID) REFERENCES
Reserve_Return(code))
Result:
3/20/2018 DBI202 – DATABASE SYSTEM OF library management system 14