OEP Dbms PDF
OEP Dbms PDF
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
Branch:
Employee:
Customer:
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.
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
1. Display the customer name who took the book of type comedy.
select customer_name from customer wherebook_type=’comedy’;
DELIMITER //
IN p_customer_id INT
BEGIN
-- Declare variables
FROM issue_status
-- Open cursor
OPEN cur_issued_books;
-- Display header
-- Start loop
read_loop: LOOP
IF done THEN
LEAVE read_loop;
END IF;
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 //
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 //
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.