0% found this document useful (0 votes)
28 views20 pages

OEP Dbms PDF

Uploaded by

Shreesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views20 pages

OEP Dbms PDF

Uploaded by

Shreesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Database Management System

Additional Group Activity report


On
Library Management System

Submitted for the partial fulfillment of Bachelor of Engineering


By
Shreesha M S Kashyap(1SI21CS098)
Shivanag T A(1SI21CS097)
P Yagnesh Sai(1SI21CS071)

Under the guidance of


Dr. Srinivasa K
Assistant professor

Department of Computer Science and Engineering


(Program Accredited by NBA)

Siddaganga Institute of Technology, Tumakuru – 572103


(An autonomous institution affiliated to VTU, Belagavi, Approved by AICTE, New Delhi,
Accredited by NAAC with 'A++' grade & ISO 9001:2015 Certified)
Library Management System
Requirement Collection

Entities

• BRANCH
• EMPLOYEE
• CUSTOMER
• ISSUE STATUS
• RETURN STATUS
• BOOKS

Attributes

❖ BRANCH
➢ Manager_id
➢ Branch_id
➢ Address
▪ Contact_no
▪ Branch_h_no
▪ Street
▪ City
▪ State
▪ Zipcode
❖ CUSTOMER
➢ Customer_id
➢ Books_issued
➢ Name
➢ Address
➢ Registration_date
❖ ISSUE STATUS
➢ Issue_book_name
➢ Issue_id
➢ Issue_date
➢ ISBN
➢ Customer_id
❖ RETURN STATUS
➢ Return_id
➢ Return_date
➢ Customer_id
➢ Return_book_name
➢ ISBN

❖ Books
➢ ISBN
➢ Title
➢ Category
➢ Rental_price
➢ Author
➢ Publisher
➢ Status

RELATIONSHIPS - CARDINALITY

❖ MANAGER manages the BRANCH (1 - N)


❖ CUSTOMER registers in the respective BRANCH (N – 1)
❖ CUSTOMER issues BOOKS (1 – N)
❖ CUSTOMER returns BOOKS (N – 1)
❖ EMPLOYEE updates BOOKS (N – N)
ER Model
Relational Mapping
Normalization up to BCNF

To apply Boyce-Codd Normal Form (BCNF) to the given library management


system ER model, we need to ensure that all functional dependencies in the
schema are represented correctly. Then, we can check if any non-trivial functional
dependencies violate BCNF and decompose the schema accordingly.

Let's analyze the functional dependencies for each entity:

Branch:

branch_id -> manager_id, address


address -> state, zip, street, city, contact_no

Employee:

employ_id -> position


branch_no -> employ_id (assuming each employee belongs to only one branch)

Customer:

customer_id -> books_issued, name, address, registration_date


branch_no -> customer_id (assuming each customer belongs to only one branch)

Based on the functional dependencies, we can observe that the entities are already
in BCNF because each determinant (left-hand side of the arrow "->") is a candidate
key for the corresponding entity. Therefore, no further decomposition is required to
satisfy BCNF.

However, if we assume that an employee or a customer can be associated with


multiple branches, we need to normalize further. Let's consider this scenario:

If an employee can work in multiple branches, then the dependency branch_no ->
employ_id in the Employee entity violates BCNF. We need to decompose the
Employee entity into two separate entities: Employee and
EmployeeBranchAssignment. Employee will have employ_id as the primary key,
and EmployeeBranchAssignment will have branch_no and employ_id as the
composite primary key.
Similarly, if a customer can register in multiple branches, we need to decompose
the Customer entity in a similar manner.

After decomposition, all entities will satisfy BCNF. However, it's crucial to
consider the actual requirements and constraints of the system before performing
any normalization.

DDL statements

CREATE TABLE BOOKS(ISBN int(100) not null,


book_title varchar(50) not null,
category varchar(50) not null,
rental_price int(10) not null,
status varchar(50),
author varchar(50) not null,
publisher varchar(50) notnull,
primary key(ISBN)) ;

CREATE TABLE EMPLOYEE(employ_id int(10) not null,


employ_name varchar(50) not null,
position varchar(30) not null,
salaryint(10) not null,
primary key(employ_id));

create table customer(customer_id int(10) not null,


customer_name varchar(50),
customer_address varchar(100) not null,
registration_date date notnull,
primary key(customer_id));

create table branch(branch_no int(10) not null,


manager_id int(10) not null,
branch_address varchar(100) not null,
contact_no int(10) not null,
primarykey(branch_no));

create table issue_status(issue_id int(10) not null,


issued_cust int(10) notnull,
issued_book_name varchar(50) not null,
issue_date date not null,
isbn_book int(10) not null,
primary key(issue_id),
constraint foreign key(isbn_book) references BOOKS(ISBN),
constraint foreign key(issued_cust) references customer(customer_id));

create table return_status(return_id int(10) not null,


return_cust int(10) not null,
returned_book_name varchar(50) not null,
return_date date not null,
isbn_book2 int(10) not null,
primary key(return_id),
constraint foreign key(isbn_book2) references BOOKS(ISBN),
constraint foreign key(return_cust)references issue_status(issued_cust));
Insert statements

insert into books


values(1000,'book1','comedy',5,'available','author1','pub1');

insert into books


values(1001,'book2','scifi',3,'available','author2','pub2');

insert into books values(1003,'book3','romance',1,'un-


available','author3','pub3');
insert into books
values(1004,'book4','thriller',7,'available','author4','pub4');

alter table branch add constraint foreign key(manager_id) references employee(employ_id);


insert into employee values(991,'emp1','manager',30000);

insert into employee values(992,'emp2','worker',10000);

insert into employee values(993,'emp3','worker',10000);

insert into employee values(994,'emp4','reader',20000);

insert into employee values(995,'emp5','assist',20000);

insert into branch values(1,991,'branch_addr1',987654321);

insert into branch values(3,993,'branch_addr3',987654323);


insert into customer values(11,'cus1','hom1','2008:10:10');

insert into customer values(12,'cus2','hom2','2008:03:03');

insert into customer values(13,'cus3','hom3','2009:03:03');

insert into customer values(14,'cus4','hom4','2009:04:04');

insert into issue_status values(51,12,'book1','2010:01:01',1001);


insert into issue_status values(52,14,'book4','2010:01:01',1004);

insert into return_status values(62,12,'book1','2010:10:01',1001);


Queries

1. Display the customer name who took the book of type comedy.
select customer_name from customer wherebook_type=’comedy’;

2. Display issue id ,issued customer name whose ibsn


booknumber is 1004.

select issue_id , issued_cust from issue_status where


isbn_book=1004;
3. Display all contents in issue status table where isbn book
ofissue table and return table are equal.

select p.* from issue_status p, return_status r where


p.isbn_book=r.isbn_book2;

4. Add a column called book type in customer table.


alter table customer add book_type varchar(10) not
null;
Stored procedures

DELIMITER //

CREATE PROCEDURE GetIssuedBooksByCustomer(

IN p_customer_id INT

BEGIN

-- Declare variables

DECLARE done BOOLEAN DEFAULT FALSE;

DECLARE v_issue_id INT;

DECLARE v_book_title VARCHAR(50);

DECLARE v_issue_date DATE;

-- Declare cursor for fetching issued books

DECLARE cur_issued_books CURSOR FOR

SELECT issue_id, issued_book_name, issue_date

FROM issue_status

WHERE issued_cust = p_customer_id;

-- Declare handler for NOT FOUND condition

DECLARE CONTINUE HANDLER FOR NOT FOUND SET


done = TRUE;

-- Open cursor
OPEN cur_issued_books;

-- Display header

SELECT 'Issue ID', 'Book Title', 'Issue Date';

-- Start loop

read_loop: LOOP

-- Fetch issued book details

FETCH cur_issued_books INTO v_issue_id, v_book_title,


v_issue_date;

-- Check if no more rows

IF done THEN

LEAVE read_loop;

END IF;

-- Display issued book details

SELECT v_issue_id, v_book_title, v_issue_date;

END LOOP;

-- Close cursor

CLOSE cur_issued_books;

END //

DELIMITER ;
This stored procedure GetIssuedBooksByCustomer takes the customer_id as input
and retrieves the list of books issued by that customer.
It fetches the issue ID, book title, and issue date from the issue_status table using a
cursor and displays them.
You can call this procedure by passing the customer ID as an argument to retrieve
the list of books issued by that customer.

CALL GetIssuedBooksByCustomer(12);

Triggers

DELIMITER //

CREATE TRIGGER UpdateBookStatusAfterIssueOrReturn


AFTER INSERT ON issue_status
FOR EACH ROW
BEGIN
-- Update book status to 'Issued' when a new entry is made in issue_status table
UPDATE BOOKS
SET status = 'Issued'
WHERE ISBN = NEW.isbn_book;
END //

DELIMITER ;
This trigger UpdateBookStatusAfterIssueOrReturn is activated after a new row is inserted into
the issue_status table.

It updates the status column of the corresponding book in the BOOKS table to 'Issued' whenever
a book is issued.

ii) DELIMITER //

CREATE TRIGGER UpdateBookStatusAfterReturn


AFTER INSERT ON return_status
FOR EACH ROW
BEGIN
-- Update book status to 'Available' when a new entry is made in return_status table
UPDATE BOOKS
SET status = 'Available'
WHERE ISBN = NEW.isbn_book2;
END //

DELIMITER ;

This trigger UpdateBookStatusAfterReturn is activated after a new row is inserted into the
return_status table.
It updates the status column of the corresponding book in the BOOKS table to 'Available'
whenever a book is returned.

You might also like