0% found this document useful (0 votes)
6 views

Assignment 1 DB

The document outlines an assignment for designing a mini database for a local library in Peshawar, focusing on managing book inventory, members, and borrowing records. It includes key entities and attributes, an entity-relationship diagram, a relational schema, and SQL queries for data retrieval. Additionally, it poses reflection questions regarding challenges in defining relationships and the importance of primary and foreign keys in maintaining data integrity and consistency.

Uploaded by

unafees2003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Assignment 1 DB

The document outlines an assignment for designing a mini database for a local library in Peshawar, focusing on managing book inventory, members, and borrowing records. It includes key entities and attributes, an entity-relationship diagram, a relational schema, and SQL queries for data retrieval. Additionally, it poses reflection questions regarding challenges in defining relationships and the importance of primary and foreign keys in maintaining data integrity and consistency.

Uploaded by

unafees2003
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

University of Engineering and Technology Peshawar

Department of Computer Science and Information Technology


Name: Nafees Ahmad
Reg No: 23PWBCS1040
Assignment: 1
Submitted to: Ayesha Noor
Submission Date: 20-03-2025
Assignment 1

Build a Mini Database for a Local Library

Scenario:

Peshawar’s local library manages its book inventory, members, and borrowing records
manually.

They want to digitize their system to improve e iciency. As database consultant, you
are

required to propose an initial database design to handle the library’s core operations.

1. Identify Key Entities & Attributes:

 Determine the main entities (e.g., Books, Members, Borrow Records and others).

 List attributes for each entity (e.g., Book_ID, Title, Author, Issue_Date and others).

2. Create an Entity-Relationship (ER) Diagram:

 Model relationships between entities (e.g., Members borrow Books).

 Show cardinality (one-to-many, many-to-many) and necessary constraints.

3. Design a Relational Schema:

 Convert the ER model into tables with proper attributes.

 Define primary keys, foreign keys, and ensure attributes have valid data types.

4. Demonstration

Demonstrate data retrieval by executing the following sample queries:

 Retrieve all books currently borrowed by a specific member.

 List all overdue books with member details.

 Show the most borrowed books using aggregate functions.

 Display member details along with their borrowing history using JOINs.

5. Reflection Questions:

 What challenges did you face in defining relationships?

 How does a primary key help maintain data integrity?

 How could foreign keys enforce consistency?


Submission Guidelines:

 Submit your ER diagram, relational schema, and SQL scripts.

 Include answers to the reflection questions.

Mini Database for Peshawar’s Local Library

1. Key Entities & Attributes

Entities and Their Attributes:

1. Books

o Book_ID (Primary Key)

o Title

o Author

o Genre

o Publication_Year

o ISBN

o Availability_Status (Available, Borrowed)

2. Members

o Member_ID (Primary Key)

o First_Name

o Last_Name

o Email

o Phone_Number

o Membership_Start_Date

o Membership_Expiry_Date

3. Borrow_Records

o Borrow_ID (Primary Key)

o Book_ID (Foreign Key referencing Books)


o Member_ID (Foreign Key referencing Members)

o Issue_Date

o Due_Date

o Return_Date (Nullable)

o Status (Borrowed, Returned, Overdue)

4. Librarians

o Librarian_ID (Primary Key)

o First_Name

o Last_Name

o Email

o Phone_Number

o Employee_ID

5. Reservations (Optional)

o Reservation_ID (Primary Key)

o Book_ID (Foreign Key referencing Books)

o Member_ID (Foreign Key referencing Members)

o Reservation_Date

o Status (Pending, Completed, Cancelled)

2. Entity-Relationship (ER) Diagram

 Books and Members have a many-to-many relationship via Borrow_Records.

 One Member can borrow multiple Books, but each Borrow_Record is linked to one
Book.

 Librarians manage borrowing records.

 Reservations help manage future borrow requests.

(ER Diagram to be included separately in the final submission.)

3. Relational Schema
Books (Book_ID, Title, Author, Genre, Publication_Year, ISBN, Availability_Status)
Members (Member_ID, First_Name, Last_Name, Email, Phone_Number,
Membership_Start_Date, Membership_Expiry_Date)
Borrow_Records (Borrow_ID, Book_ID, Member_ID, Issue_Date, Due_Date,
Return_Date, Status)
Librarians (Librarian_ID, First_Name, Last_Name, Email, Phone_Number,
Employee_ID)
Reservations (Reservation_ID, Book_ID, Member_ID, Reservation_Date, Status)

Primary and Foreign Keys:

 Primary Keys: Book_ID, Member_ID, Borrow_ID, Librarian_ID, Reservation_ID.

 Foreign Keys:

o Book_ID (in Borrow_Records, Reservations) → References Books(Book_ID)

o Member_ID (in Borrow_Records, Reservations) → References


Members(Member_ID)

4. SQL Queries for Demonstration

1. Retrieve all books currently borrowed by a specific member:

2. List all overdue books with member details:

3. Show the most borrowed books using aggregate functions:

4. Display member details along with their borrowing history using JOINs:

5. Reflection Questions

1. What challenges did you face in defining relationships?

 Ensuring a proper many-to-many relationship between Books and Members via


Borrow_Records.

 Handling scenarios where a book is reserved but not yet borrowed.

 Managing overdue statuses dynamically.

2. How does a primary key help maintain data integrity?

 Ensures each record in a table is unique.

 Prevents duplication of books, members, and borrowing records.

 Helps in e iciently retrieving and managing data.


3. How could foreign keys enforce consistency?

 Ensures that borrow records reference valid books and members.

 Prevents orphaned records by restricting deletion of referenced data.

 Maintains referential integrity between tables.

You might also like