UNIVERSITY OF THE PEOPLE (UoPeople)
CS 2203-01 - Databases 1
Lutalo Martin
BSc. Computer Science
CS 2203-01 - AY2025-T4 / Programming Assignment Unit 5
Instructor Baraka Laiza
15th May 2025
Improving the functionality of library databases through schema modification and
author integration
Introduction
The task of the assignment is to enhance the previous library management system by
creating a new entity, populating the database with relevant sample data, and using SQL
to perform management and retrieval of details. The key purpose is to develop a greater
understanding of SQL's Data Definition Language (DDL) and Data Manipulation
Language (DML), in order to manage real-life situations.
a) Database Extension and Data Population
Create Authors Table
CREATE TABLE Authors (
AuthorID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Nationality VARCHAR(50),
BirthYear INT
);
Sample Data Insertion (Ugandan Names)
-- Insert authors
INSERT INTO Authors VALUES
(1, 'Okello Peter', 'Ugandan', 1975),
(2, 'Nabirye Grace', 'Ugandan', 1980),
(3, 'Mukasa John', 'Ugandan', 1968),
(4, 'Kaggwa Sarah', 'Ugandan', 1985),
(5, 'Wanyama Brian', 'Ugandan', 1990);
-- Insert additional books
INSERT INTO Books VALUES
('9780131103627', 'The C Programming Language', 'Okello Peter', 'Programming', 5),
('9780596009205', 'Head First Java', 'Nabirye Grace', 'Programming', 3),
('9781449355739', 'Learning Python', 'Mukasa John', 'Programming', 4),
('9780321751041', 'Effective Java', 'Okello Peter', 'Programming', 2),
('9780132350884', 'Clean Code', 'Kaggwa Sarah', 'Software Engineering', 6),
('9781491954249', 'Fluent Python', 'Wanyama Brian', 'Programming', 1),
('9780134685991', 'Refactoring', 'Nabirye Grace', 'Software Engineering', 2),
('9780134494166', 'Agile Principles', 'Mukasa John', 'Agile', 5),
('9781492078005', 'JavaScript Guide', 'Wanyama Brian', 'Web Development', 3),
('9781491919538', 'High Performance Python', 'Kaggwa Sarah', 'Programming', 2);
-- Insert 20 Ugandan members
INSERT INTO Members VALUES
(1, 'Lutalo Martin', '[email protected]', '0703533442'),
(2, 'Mukiibi Mark', '[email protected]', '0779269605'),
(3, 'Nansubuga Rachel', '[email protected]', '0701234567'),
(4, 'Kabanda Tom', '[email protected]', '0777654321'),
(5, 'Nakato Joan', '[email protected]', '0709876543'),
(6, 'Ocen Emmanuel', '[email protected]', '0780123456'),
(7, 'Namugga Edith', '[email protected]', '0777000001'),
(8, 'Kisakye Brian', '[email protected]', '0708000002'),
(9, 'Ssemanda Ronald', '[email protected]', '0788666444'),
(10, 'Akello Sharon', '[email protected]', '0777123456'),
(11, 'Lumu Isaac', '[email protected]', '0709090909'),
(12, 'Bbosa Kenneth', '[email protected]', '0788002233'),
(13, 'Kaggwa Brenda', '[email protected]', '0777333444'),
(14, 'Tumusiime Faith', '[email protected]', '0701222333'),
(15, 'Zziwa George', '
[email protected]', '0788111222'),
(16, 'Kintu Alex', '[email protected]', '0777888999'),
(17, 'Nakanwagi Doreen', '[email protected]', '0703000111'),
(18, 'Okello Denis', '[email protected]', '0788222333'),
(19, 'Namirembe Ruth', '[email protected]', '0777444555'),
(20, 'Ssekyewa Paul', '[email protected]', '0701555666');
b) SQL Operations
i. Retrieve All Books by a Specific Author
Example: Okello Peter
SELECT * FROM Books WHERE Author = 'Okello Peter';
ii. Drop the Authors Table
DROP TABLE Authors;
[Include screenshot showing successful execution of the drop command]
c) Retrieve Names of All Members Who Borrowed a Specific Book
SELECT Members.Name
FROM Members
JOIN Loans ON Members.MemberID = Loans.MemberID
WHERE Loans.ISBN = '9780131103627';
[Include screenshot of query and results]
d) Alter Members Table to Add Membership Type
ALTER TABLE Members
ALTER TABLE Members ADD MembershipType VARCHAR(20);
Full script.
-- TABLE CLEANUP (FOR RESETTING DATABASE)
DROP TABLE IF EXISTS Loans;
DROP TABLE IF EXISTS Members;
DROP TABLE IF EXISTS Books;
DROP TABLE IF EXISTS Authors;
-- TABLE CREATION
CREATE TABLE Authors (
AuthorID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Nationality VARCHAR(50),
BirthYear INT
);
CREATE TABLE Books (
ISBN VARCHAR(13) PRIMARY KEY,
Title VARCHAR(100) NOT NULL,
Author VARCHAR(100) NOT NULL,
Genre VARCHAR(50),
Quantity INT DEFAULT 1 CHECK (Quantity >= 0)
);
CREATE TABLE Members (
MemberID INT PRIMARY KEY,
Name VARCHAR(100) NOT NULL,
Email VARCHAR(100) UNIQUE,
Phone VARCHAR(15)
);
CREATE TABLE Loans (
LoanID INT PRIMARY KEY,
MemberID INT NOT NULL,
ISBN VARCHAR(13) NOT NULL,
LoanDate DATE DEFAULT CURRENT_DATE,
ReturnDate DATE,
FOREIGN KEY (MemberID) REFERENCES Members(MemberID) ON DELETE
CASCADE,
FOREIGN KEY (ISBN) REFERENCES Books(ISBN) ON DELETE CASCADE,
CONSTRAINT chk_dates CHECK (ReturnDate > LoanDate)
);
-- DATA INSERTION
INSERT INTO Authors VALUES
(1, 'Okello Peter', 'Ugandan', 1975),
(2, 'Nabirye Grace', 'Ugandan', 1980),
(3, 'Mukasa John', 'Ugandan', 1968),
(4, 'Kaggwa Sarah', 'Ugandan', 1985),
(5, 'Wanyama Brian', 'Ugandan', 1990);
INSERT INTO Books VALUES
('9780131103627', 'The C Programming Language', 'Okello Peter', 'Programming', 5),
('9780596009205', 'Head First Java', 'Nabirye Grace', 'Programming', 3),
('9781449355739', 'Learning Python', 'Mukasa John', 'Programming', 4),
('9780321751041', 'Effective Java', 'Okello Peter', 'Programming', 2),
('9780132350884', 'Clean Code', 'Kaggwa Sarah', 'Software Engineering', 6),
('9781491954249', 'Fluent Python', 'Wanyama Brian', 'Programming', 1),
('9780134685991', 'Refactoring', 'Nabirye Grace', 'Software Engineering', 2),
('9780134494166', 'Agile Principles', 'Mukasa John', 'Agile', 5),
('9781492078005', 'JavaScript Guide', 'Wanyama Brian', 'Web Development', 3),
('9781491919538', 'High Performance Python', 'Kaggwa Sarah', 'Programming', 2);
INSERT INTO Members VALUES
(1, 'Lutalo Martin', '[email protected]', '0703533442'),
(2, 'Mukiibi Mark', '[email protected]', '0779269605'),
(3, 'Nansubuga Rachel', '[email protected]', '0701234567'),
(4, 'Kabanda Tom', '[email protected]', '0777654321'),
(5, 'Nakato Joan', '[email protected]', '0709876543'),
(6, 'Ocen Emmanuel', '[email protected]', '0780123456'),
(7, 'Namugga Edith', '
[email protected]', '0777000001'),
(8, 'Kisakye Brian', '[email protected]', '0708000002'),
(9, 'Ssemanda Ronald', '[email protected]', '0788666444'),
(10, 'Akello Sharon', '[email protected]', '0777123456'),
(11, 'Lumu Isaac', '[email protected]', '0709090909'),
(12, 'Bbosa Kenneth', '[email protected]', '0788002233'),
(13, 'Kaggwa Brenda', '[email protected]', '0777333444'),
(14, 'Tumusiime Faith', '[email protected]', '0701222333'),
(15, 'Zziwa George', '[email protected]', '0788111222'),
(16, 'Kintu Alex', '[email protected]', '0777888999'),
(17, 'Nakanwagi Doreen', '[email protected]', '0703000111'),
(18, 'Okello Denis', '[email protected]', '0788222333'),
(19, 'Namirembe Ruth', '[email protected]', '0777444555'),
(20, 'Ssekyewa Paul', '[email protected]', '0701555666');
INSERT INTO Loans VALUES
(101, 1, '9780131103627', '2025-05-01', '2025-05-10'),
(102, 2, '9780596009205', '2025-05-03', '2025-05-13'),
(103, 3, '9780321751041', '2025-05-02', '2025-05-12'),
(104, 4, '9781449355739', '2025-05-04', '2025-05-14');
-- REQUIRED QUERIES
-- a) Retrieve all books written by a specific author
SELECT * FROM Books WHERE Author = 'Okello Peter';
-- b) Drop the newly created Authors table
DROP TABLE Authors;
-- c) Identify names of all members who have borrowed a specific book
SELECT Members.Name
FROM Members
JOIN Loans ON Members.MemberID = Loans.MemberID
WHERE Loans.ISBN = '9780131103627';
-- d) Alter the Members table to include MembershipType
ALTER TABLE Members ADD MembershipType VARCHAR(20);
Conclusion
The activities completed in this assignment provided practical experience with extending
a relational schema, writing accurate SQL commands to retrieve and modify data, and
improving the organization of data. By adding an Authors table and changing some
aspects of Members, I was able to apply normalization and other schema evolution
techniques. I could comfortably use JOIN operations, showing the advantages of the
relational model to bring together data from several tables. I used constraints and defaults
to maintain consistency. In the future I would consider doing some more normalization,
e.g. separating genres, and implementing some extended membership privileges.
References
GeeksforGeeks. (2024, September 30). SQL concepts and queries.
https://www.geeksforgeeks.org/sql-concepts-and-queries/
Peterson, R. (2023, December 26). MySQL – ALTER, DROP, RENAME, MODIFY.
GURU99. https://www.guru99.com/alter-drop-rename.html
Yadav, A. (2022, February 28). Create, Insert, Update, Delete, Select, Truncate, Drop
Statement In Oracle PL-SQL. C# Corner.
https://www.c-sharpcorner.com/article/create-insert-update-delete-select-truncate-
drop-statement-in-oracle-pl-sq/
Vidhya, V., Jeyaram, G., & Ishwarya, K. (2016). Database Management Systems. Alpha
Science International.
Codecademy. (2025, February 26). SQL Commands list: Basic database queries.
https://www.codecademy.com/article/sql-commands