1. Trang chủ
  2. » Luận Văn - Báo Cáo

group 8 database lab final project report subject library management

18 0 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 18
Dung lượng 794,31 KB

Nội dung

- Publisher Management: Containing accurate detail about the publisher - Member Management: Storing the reader’s information - Borrowing and returning process managing and storing: indic

Trang 1

School of Information and Communication Technology

-    -

Group 8 Database Lab Final Project Report

Subject: Library Management Teacher: Ms Nguy n Th Oanh ễ ị

Group 8’s members:

2 Nguyễn Trọng Bách 20226014

3 Nguyễn Đình Phúc 20226062

Hà N ội, năm 20 24

Trang 2

Contents

Topic and Description, Objectives and Usage scenario 3

I, Functionalities and Requirement 4

I.1, Functionalities 4

I.2, Requirement 4

II, Entity Relationship Diagram and Relational Schema 5

II.1.ERD 5

II.2, Relational Schema 5

III, Database description 6

IV, SQL Queries Error! Bookmark not defined V, Install functionalies 7

1 Function to count the number of borrowing for each member 7

2 Trigger when modifying borrowing 8

3 Function set a book to available stauts when a member returns a book 9

4 Function to count the number of copies for each book 9

5 trigger when modifying book_copy 10

6 Function to update number_of_books for each author 11

7 trigger when modifying book_author 11

8 trigger to delete a book copy 12

VI, Difficulties 15

VII, Evaluation 15

VIII, Task of each member 15

Trang 3

Topic and Description, Objectives and Usage scenario

In the society filled with information, it is important to store every necessary data for optimization in the managing process Data generated by stored information is critical for the analyzer to give prediction about the future

In case of library, the process of managing books and readers will be optimized a lot with the help of a well-designed database

Our topic is to make a database that stores the information of the library, including information about books, copies of books, Authors, Publishers, categories of books It will also store the list of all readers’account, their borrowing of books and the notification from the library to the users

The objectives is to give the libraries a solution to manage their huge amount of books, readers and their activities of borrowing and returning the book All the record will be stored for furthur use and management

Users are able to search for books by different criteria : Author, Title, Publisher, Categories, Description They can also see the notification of their activities of borrowing and returning books in the library

Trang 4

I, Functionalities and Requirement

1 Functionalities

- Book Management:

• Managing detailed record of a book

• Managing all copy of the book in library: Allow the staff to manage all the copy of the book of the library

- Author Management: In case readers want to find books written by an author

• Managing the Author’s name and his/her books

• Storing the Author’s Information such as his/her name, Date of Birth,

Nationality, Description,

- Book and Author Searching: Link the Book Author to allow users to search for the book and its authors

- Category Management: Allow the reader to search the type of books they want to read

• Storing book’s category, for example: Detective, Horror, Mathematics,

Scientific, Fictional,

- Publisher Management: Containing accurate detail about the publisher

- Member Management: Storing the reader’s information

- Borrowing and returning process managing and storing: indicate whether the book has been borrowed and returned back

- Notification: Storing all the users’s received notification, send the notification to the users when borrowing and returning books happened

2 Requirement

- A books can be written by multiple author and an author can write a lot of books

- A book will be associated with a category Book’s copies is distinguish with each other by a code design by the library

- Notification depends on the member list Each notification will be sent to one member

- A borrowing relation depends on the member list and the book_copy list Each borrowing can only consist of one members borrowing one book copy

- A book can have multiple book_copy but a book_copy can be associated with only one book

Trang 5

II, Entity Relationship Diagram and Relational Schema

1 ERD

2 Relational Schema

Trang 6

III, Database description

1 Books

• BookID: An unique ID to identify books, generated by the ISBN 13 code

• Title: the title of the book

• CategoryID: Foreign Key linked to the Categories_list Relation Category of a book is assigned by the librarian

• Description: The summary of a book, written by the author and the staff of the library

• Number_of_Pages: Storing the number of pages of that book

• Number_of_copies: storing the number of copies of that book

2 Author

Storing the information of the author

• AuthorID: Storing the ID of the author

• Author_name: The name of the author

• Date_of_birth: His/her birthdate

• Nationality: His/her nationality

• Description: Detailed information of the Author

• Number_of_books: storing the number of books the author wrote

3 Author_book

Storing Author and their book

• Book_ID: Storing unique books, reference to the Books Table

• AuthorID: Storing the Author’s ID, reference to the Author Table

4 Categories_list

Storing the categories bring specified by the library

• CategoryID: Storing the unique ID of the categories

• Name: Storing the full name of the category

5 Book_copy

Store the detail information about each copy of books in library

• book_copy_ID: The unique ID of the copy

• year_published: The Year it has been published

• publisher_ID: Foreign Key reference to the Publisher_detail relation

• book_ID: Foreign Key reference to the Book relation

• Is_available: The status of the book

6 Publisher_detail

The information of the publisher

• PublisherID: Unique ID of the publisher

• PublisherName: Name of the publisher

• Email: Contact email to the publisher

• phone_number: The publisher’s phone number

Trang 7

7 Member

• memberID: Unique ID is the username created by user

• DoB: The Date of birth of User

• email: the email used to recover the account in case the user forget the password

• Name: User’s Full name, typed in by the User

• Phone_number: the user’s number in case the library wants to contact the

user

• Number_of_borrowing: the number of book they have borrowed

8 Borrowing

Weak entity belongs to the strong entities Book_copy and Member

• Book_copy_id: Foreign Key links to the Book_copy relation

• Member_id: Foreign Key links to the Member relation

• Start_time: store the time they successfully borrowed a book from library

• End_time: store the time they scheduled to return the book

• Is_returned: the status attribute of a borrowed book

9 Notification

Store the notification to the user

• Notif_ID: the Id of the notification

• Member_id: Primary Key and foreign Key reference to the Member table

• Sent_at: the time to sent the notification

• content: the message the library sent (available book, request to return books)

IV, Install functionalies

1 Function to count the number of borrowing for each member

create or replace function count_borrowing()

returns void as $$

declare

borrowing_count int;

member_record varchar(40);

begin

for member_record in select memberID from member loop

select count(*) into borrowing_count

from borrowing

where memberID = member_record;

update member

Trang 8

set number_of_borrowing = borrowing_count

where memberID = member_record;

end loop;

end;

$$

LANGUAGE plpgsql;

2 Trigger when modifying borrowing

CREATE OR REPLACE FUNCTION update_book_copy_availability()

RETURNS TRIGGER AS $$

BEGIN

IF NEW.is_returned = 0 THEN

UPDATE book_copy

SET is_available = 0

WHERE book_copy_id = NEW.book_copy_id;

END IF;

RETURN NEW;

update member

set number_of_borrowing = number_of_borrowing + 1

where memberID = new.memberID;

END;

$$ LANGUAGE plpgsql;

CREATE or replace TRIGGER trigger_update_book_copy_availability

AFTER INSERT ON borrowing

FOR EACH ROW

EXECUTE FUNCTION update_book_copy_availability();

Trang 9

3 Function set a book to available stauts when a member returns a book create or replace function modify_checkout(in member_id varchar(40), in book_copy_id varchar(30), in return_date date)

returns void as $$

begin

update borrowing

set is_returned = 1

where borrowing."memberID" = member_id and borrowing."book_copy_id" = book_copy_id and borrowing."is_returned" = 0;

update book_copy

set is_available = 1

WHERE book_copy."book_copy_id" = book_copy_id;

INSERT INTO notification (notif_ID, sent_at, type, memberID)

VALUES (uuid_generate_v4(), return_date, 'Return Successful', member_id); end;

$$

language plpgsql;

4 Function to count the number of copies for each book

create or replace function count_number_of_books()

returns void as $$

declare

copies_count int;

book_record varchar(20);

begin

for book_record in select bookID from book loop

select count(*) into copies_count

from book_copy

Trang 10

where bookID = book_record;

update book

set number_of_copies = copies_count

where bookID = book_record;

end loop;

end;

$$

language plpgsql;

5 Trigger when modifying book_copy

CREATE OR REPLACE FUNCTION increase_book_copies()

RETURNS TRIGGER AS $$

BEGIN

UPDATE book

SET number_of_copies = number_of_copies + 1

WHERE bookID = NEW.bookID;

RETURN NEW;

END;

$$ LANGUAGE plpgsql;

CREATE or replace TRIGGER increase_copies_trigger

AFTER INSERT ON book_copy

FOR EACH ROW

EXECUTE FUNCTION increase_book_copies();

Trang 11

6 Function to update number_of_books for each author

create or replace function count_number_of_books_author()

returns void as $$

declare

book_count int;

author_record varchar(20);

begin

for author_record in select authorID from author loop

select count(*) into book_count

from author_book

where authorID = author_record;

update author

set number_of_books = book_count

where authorID = author_record;

end loop;

end;

$$

language plpgsql;

7 Trigger when modifying book_author

create or replace function update_number_of_books()

returns trigger as $$

begin

update author

set number_of_books = number_of_books + 1

where authorID = new.authorID;

Trang 12

end;

$$

language plpgsql;

create or replace trigger trigger_update_book_author

after insert on author_book

for each row

execute function update_number_of_books();

8 trigger to delete a book copy

create or replace function decrease_book_copies()

returns trigger as $$

begin

update book

set number_of_copies = number_of_copies - 1

where bookID = new.bookID;

end;

$$

language plpgsql;

create or replace trigger delete_book_copies

after delete on book_copy

for each row

execute function decrease_book_copies();

Trang 13

V, Database Optimization

time (without index)

Execution time (with index) Count the number of times

the book ‘Physics

Principles’ was borrowed

select b.title from book b inner join book_copy bc on b.bookID = bc.bookID inner join borrowing br on br.book_copy_id = bc.book_copy_id where b.title = 'Physics Principles';

0.938 ms 0.887 ms

Find all the member’s name

with number_of_borrowing

> 3

select name from member whe number_of_borrowing > 3;

0.662 ms 0.039 ms

Count the number of

notifications for member

with name "Nguyen Sy Tu"

select count(*) from member m inner join notification n on m.memberid = n.memberid where lower(m.name) = 'nguye

sy tu' group by m.memberid;

0.349 ms 0.436 ms

Find all author born

between 1980 and 2000 an

arrange them in ascending

order of birthdate

Select * from author where Extract(year from date_of_birth) >= 1980 And Extract(year from date_of_birth

<= 2000 order by(

date_of_birth) asc;

0.115 ms 0.104 ms

Find the author who has

Japanese nationality Select * from author where nationality = 'Japanese'; 0.040 ms 0.028 ms

Select book that has been

written by J.k Rowling Select ab.bookid, b.title from author_book ab join book b

using(bookid) join author a

0.089 ms 0.088 ms

Trang 14

using(authorid) where a.author_name like 'J.K Rowling%';

Display all the book_copy

of the book 'Harry Potter'

select bc.book_copy_id, bc.year_published, p.publisherName from book_copy bc join book b using(bookid) join publisher_detail p using(publisherid) where b.title like'Harry Potter%';

1.040 ms 0.270 m

Display publisher which

published more than 10

books in the library

select p.* from publisher_detail

p left join book_copy bc using(publisherid) group by p.publisherid having count(distinct bc.bookid) > 5;

2.860 ms 2.847 ms

Display categories that

contains more than 15

books

select c.* from categories_list c left join book b using (categoryid) group by(c.categoryid) having count(b.bookid) >15;

0.490 ms

0.612 ms

• Index used in this database :

➢ CREATE INDEX idx_publishername ON publisher_detail (publishername);

➢ CREATE INDEX idx_number_of_copies ON book (number_of_copies);

➢ CREATE INDEX idx_number_of_books ON author (number_of_books) ;

➢ CREATE INDEX idx_title ON book (title);

➢ CREATE INDEX idx_member_name ON member (name);

• Explanation for the usage of index in this database :

➢ Because we mainly perform searching statements on tables publisher_detail, books, author, member, we use indices to enhance the queries’ performance

Trang 15

each statement that we carry out, the DBMS will have to restructrure the index

in the table not effective →

VI, Difficulties

• Diffuculties in handling the borrowing process : When we borrow a book, how can

we show that the book copy has been borrowed ?

➔ Solution: add an attributes in a book_copy relation : is_available, will take the value of 0 if it’s borrowed, 1 if have not been borrowed yet

• The notification to the readers is an essential function to give readers infomation about their borrowing and returning books How can we stored all the notification that the library sent to them ? How to get this process works automatically ?

➔ Solution: Since notfication can not exist without member → It’s a weak entity So

we need to set the Foreign key reference to the memberid in Member relation, and

a key in notification to form a composite primary key can store multiple → notification of members To sent notification automatically, we need to create triggers to indicate whether a book is borrowed, sent notification to the member that have same memberID as the borrower The same goes with the returning book process

VII, Evaluation

• Advantages :

➢ Basically handle the problems of library management, fulfil some

functionalities and all requirements

➢ Define the relationships between tables in the database, such as book and author, member and borrowing, pubisher detail

• Disadvanges :

➢ Database has’t got a functionality to handle the case that some members in the library want to hold (reserve) book

➢ Database hasn’t handled the funtionality for staff managment

VIII, Task of each member

Nguyễn Đình Phúc : write reports, contribute to making ERD, input data sample,

create queries and contribute to optimizing the queries

Ngày đăng: 29/05/2024, 18:09

w