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

Database Programming Assignment Unit 5

This document outlines a programming assignment for a Computer Science degree, focusing on extending a library database schema by adding an Authors table and performing various SQL operations. It includes steps for creating the table, populating it with sample data, and executing SQL queries for retrieving information and modifying the database. The assignment aims to demonstrate effective database management skills through practical application of SQL commands.

Uploaded by

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

Database Programming Assignment Unit 5

This document outlines a programming assignment for a Computer Science degree, focusing on extending a library database schema by adding an Authors table and performing various SQL operations. It includes steps for creating the table, populating it with sample data, and executing SQL queries for retrieving information and modifying the database. The assignment aims to demonstrate effective database management skills through practical application of SQL commands.

Uploaded by

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

Programming Assignment Unit 5

An Assignment submitted in partial fulfillment


of the requirements for the degree of
Bachelor of Science
in
Computer Science

CS 2203 – Databases
Term 1 - 2025
University of The People

October 8, 2024,
Library Database Management Assignment

In this assignment, we will extend the existing library database schema by adding an Authors table and
populating it with sample data. We will also perform various SQL operations as specified in the
assignment.

Step 1: Database Schema Extension

Create the Authors Table

The Authors table will include the following attributes:

 AuthorID: Unique identifier for each author (Primary Key).

 Name: Name of the author.

 Nationality: Nationality of the author.

 BirthYear: Year of birth of the author.

SQL Command to Create Authors Table:

Sql code

CREATE TABLE Authors (

AuthorID INT AUTO_INCREMENT PRIMARY KEY,

Name VARCHAR(255) NOT NULL,

Nationality VARCHAR(100),

BirthYear INT

);

Step 2: Populate Tables with Sample Data


A. Inserting Sample Data into Authors Table

Sql code

INSERT INTO Authors (Name, Nationality, BirthYear) VALUES

('F. Scott Fitzgerald', 'American', 1896),

('George Orwell', 'British', 1903),


('Harper Lee', 'American', 1926),

('J.K. Rowling', 'British', 1965),

('Mark Twain', 'American', 1835);

INSERT INTO Books (ISBN, Title, Author, Genre, Quantity) VALUES

('978-3-16-148410-0', 'The Great Gatsby', 'F. Scott Fitzgerald', 'Fiction', 5),

('978-0-14-028333-4', '1984', 'George Orwell', 'Dystopian', 8),

('978-0-06-112008-4', 'To Kill a Mockingbird', 'Harper Lee', 'Fiction', 3),

('978-0-7475-3274-2', 'Harry Potter and the Sorcerer\'s Stone', 'J.K. Rowling', 'Fantasy', 10),

('978-0-452-28423-4', 'Adventures of Huckleberry Finn', 'Mark Twain', 'Fiction', 7),

('978-1-56619-909-4', 'Animal Farm', 'George Orwell', 'Political Satire', 6),

('978-0-7432-7356-5', 'The Catcher in the Rye', 'J.D. Salinger', 'Fiction', 4),

('978-0-7432-7357-2', 'Pride and Prejudice', 'Jane Austen', 'Romance', 5),

('978-0-06-440766-1', 'The Adventures of Tom Sawyer', 'Mark Twain', 'Fiction', 8),

('978-0-14-243724-7', 'Go Set a Watchman', 'Harper Lee', 'Fiction', 3);

INSERT INTO Members (Name, Email, Phone) VALUES

('John Doe', '[email protected]','+1 332 456 342'),

('Jane Smith','[email protected]','+23 35 564 343'),

('Alice Johnson','[email protected]','+24 34 456 345'),

('Bob Brown','[email protected]','+23 56 987 678'),

('Charlie Davis','[email protected]','+1 45 789 563'),

('Diana Evans','[email protected]','+256 789 034'),

('Ethan Foster','[email protected]','+452 08 697 443'),

('Fiona Green','[email protected]','+1 28 856 345'),


('George Harris','[email protected]','+1 890 167 342'),

('Hannah Iversen','[email protected]','+23 91 678 342'),

('Ian Johnson','[email protected]','+254 34 567 189'),

('Julia King','[email protected]','+12 89 091 198'),

('Kevin Lee','[email protected]','(+9 234 567 890'),

('Laura Martinez','[email protected]','+17 45 678 013'),

('Michael Nguyen','[email protected]','+1 456 79 124'),

('Nina Connor','[email protected]','+54 567 89 215'),

('Oscar Patel','[email protected]','+14 67 901 146'),

('Paula Quinn','[email protected]','+1 789 923 457'),

('Quinn Roberts','[email protected]','+19 90 568 167'),

('Rachel Smith','[email protected]','+1 901 456 179');

Step 3: SQL Queries for Operations

A. Retrieve All Books Written by a Specific Author

To retrieve all books written by a specific author (e.g., George Orwell):

Sql code

SELECT *

FROM Books

WHERE Author = 'George Orwell';

B. Drop the Newly Created Authors Table

If you need to remove the Authors table from your database:


Sql code

DROP TABLE Authors;

C. Identify Names of All Members Who Have Borrowed a Specific Book

To find out which members have borrowed a specific book (e.g., "1984"):

Sql code

SELECT m.Name

FROM Members m

JOIN Loans 1 ON m.MemberID = l.MemberID

JOIN Books b ON 1.ISBN = b.ISBN

WHERE b.Title = '1984';

D. Alter Members Table to Include a New Attribute "MembershipType"

To add a new column called MembershipType to distinguish between different types of memberships:

Sql code

ALTER TABLE Members

ADD MembershipType VARCHAR(50);


Conclusion

This assignment demonstrates how to create and manipulate a library database schema effectively while
performing various SQL operations to manage books, members, and loans.

References

1. Elmasri, R., & Navathe, S. B. (2015). Fundamentals of Database Systems (7th ed.). Pearson.

2. Harrington, J. L. (2016). Relational Database Design Clearly Explained (3rd ed.). Morgan
Kaufmann.

You might also like