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

Database Assignment (Group 2)

The document describes a database for a comics and novels rental company. It includes entities for branches, staff, customers, books, authors, and rental transactions. The entity relationship diagram and relational schema map the entities and their relationships. Data dictionaries define the attributes for each entity with their data types, constraints, and keys. Sample data and queries are included to demonstrate creating and interacting with the database tables.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Database Assignment (Group 2)

The document describes a database for a comics and novels rental company. It includes entities for branches, staff, customers, books, authors, and rental transactions. The entity relationship diagram and relational schema map the entities and their relationships. Data dictionaries define the attributes for each entity with their data types, constraints, and keys. Sample data and queries are included to demonstrate creating and interacting with the database tables.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Sunway DIIT Database Fundamental I

DIPLOMA IN INFORMATION TECHNOLOGY

Subject: DATABASE FUNDAMENTAL 1


Subject code: DIT1333
Group Name: Group 2
Lecturer: Ms Kwong Siaw Chun
Date of Submission: 8 November 2021

Name Student ID

Max Liew Zee Kit 21016506

Nguyen Chi Thanh 21016217

Wong Hoe Yin 21015078

Academic Honesty Acknowledgement


“We verify that this paper contains entirely my work. We have not consulted with any outside person or
materials other than what was specified (an interviewee, for example) in the assignment or the syllabus
requirements. Further, we have not copied or inadvertently copied ideas, sentences, or paragraphs from
another student. we realize the penalties (refer to the student handbook diploma and undergraduate
programme) for any kind of copying or collaboration on any assignment.”

Name Signature Date


Max Liew Zee Kit Mx 8/11/2021
Nguyen Chi Thanh Than 8/11/2021
Wong Hoe Yin Why 8/11/2021

Workload Matrix of Group Members


Name Student ID Signature Roles & Responsibilities
Modelled the database, developed the ERD and
relational schema, drew the ERD and relational schema
using draw.io, developed the data dictionary, set the
Max Liew
21016506 Mx design parameters and constraints, wrote the codes to
Zee Kit
create the database (DDL), inserted the test data, wrote
the codes to answer queries (I to V) and output the
screens (DML), and compiled the report.
Nguyen Chi
21016217 Thanh Content, ER Diagram
Thanh
Wong Hoe
21015078 Why ER diagram, conclusion
Yin

Page 1/25
Sunway DIIT Database Fundamental I

Table of Content

1. Introduction

1.1 Background Information

1.2 Objectives

1.3 Business Assumption

2. Entity Relationship Diagram (ERD)

3. Relationship Schema

4. Data Dictionary

5. SQL Statements

5.1 Data Definition Language (DDL)


5.1.1 DDL Codes
5.1.2 Screenshots of Programs

5.2 Data Manipulation Language (DML)

5.2.1 DML Codes (Injecting Data into Tables)


5.2.2 Screenshots of Programs (Injecting Data into Tables)

5.2.3 DML Codes (Query I)


5.2.4 Screenshots of Programs (Query I)

5.2.5 DML Codes (Query II)


5.2.6 Screenshots of Programs (Query II)

5.2.7 DML Codes (Query III)


5.2.8 Screenshots of Programs (Quey III)

5.2.9 DML Codes (Query IV)


5.2.10 Screenshots of Programs (Query IV)

5.2.11 DML Codes (Query V)


5.2.12 Screenshots of Programs (Query V)

6. Conclusion

Page 2/25
Sunway DIIT Database Fundamental I

1. INTRODUCTION

1.1 Background Information

Welcome to Comics & Novels Rental Company. This is a database designed to manage
the company’s essential data for the smooth and efficient running of the book rental
operations. We call the database ‘BookRentalCo’. The key data include the following are:

Branch
Staff
Customer + cTel (Multivalue Attribute)
Book (Catalogue)
Author + AuthorCatalogue (Multivalue Attribute)
BookCopies (Stock)
Rental

1.2 Design Objective

The design objectives of the database are:

● Process flow to be modelled by Entity Relationship Diagram (ERD).


● ERD to be transferred to Relational Schema.
● Constraints are documented in data dictionary.
● System to be user-friendly.
● Data to be useful, accurate and updated for ease of retrieval.

1.3 Business Assumption

Comins & Novels Rental Company is a Malaysian company with branches in Malaysia.

Customers are allowed to rent books from any of our branches throughout Malaysia using
the same customer ID.

Provision has been made for multiple authors to a book.

Page 3/25
Sunway DIIT Database Fundamental I

2. ENTITY RELATION DIAGRAM (ERD)

Page 4/25
Sunway DIIT Database Fundamental I

3. RELATIONAL SCHEMA

Figure 2. Relational Schema

Page 5/25
Sunway DIIT Database Fundamental I

4. DATA DICTIONARY

Branch
Attribute Type Constraint Key Description

bID varchar(10) Not Null Primary Branch ID

bName varchar(15) Not Null, Branch name


Unique

bTel varchar(15) Not Null Branch telephone number

bAddress - - Branch address (composite


attribute)

bLot varchar(7) Null Branch lot

bStreet varchar(20) Null Branch street

bArea varchar(20) Not Null Branch area

bPostcode int(10) Null Branch postcode

bState varchar(15) Not Null Branch state

Staff
Attribute Type Constraint Key Description

sID varchar(10) Not Null Primary Staff ID

sName - - Staff name (composite


attribute)

sFName varchar(10) Not Null Staff first name

sLName varchar(10) Not Null Staff last name

sPosition varchar(25) Not Null Staff position

sSalary float(7,2) Not Null Staff salary

sBID* varchar(10) Not Null Foreign Branch ID

Page 6/25
Sunway DIIT Database Fundamental I

4. DATA DICTIONARY (Cont.)

Customer
Attribute Type Constraint Key Description

cID varchar(10) Not Null Primary Customer ID

cName - Not Null Customer name

cFName varchar(10) Not Null Customer first name

cLName varchar(10) Not Null Customer last name

cAddress - - Customer address (composite


attribute)

cLot varchar(5) Not Null Customer lot

cStreet varchar(30) Not Null Customer street

cArea varchar(30) Not Null Customer area

cPostcode int(10) Not Null Customer postcode

cState varchar(10) Not Null Customer state

cDateRegistered date Not Null Customer registered date

cBID* varchar(10) Not Null Foreign Branch ID

cTel (Multivalue Attribute)


Attribute Type Constraint Key Description

cTelID* varchar(10) Not Null Foreign Customer ID

cTel varchar(15) Not Null Customer telephone number


(multivalues)

Page 7/25
Sunway DIIT Database Fundamental I

4. DATA DICTIONARY (Cont.)

Book
Attribute Type Constraint Key Description

catID varchar(10) Not Null Primary Catalogue ID

Title varchar(40) Not null Book title

Type varchar(20) Not Null Book type (Novel, Comic,


etc.)

Category varchar(20) Not Null Book category (Horror,


Children, Romance, etc.)

DailyRental float(5,2) Not Null Book daily rental

Cost float(5,2) Not Null Book cost

QuantityOnHand int(5) Not Null Quantity of books on hand in


branch

Author
Attribute Type Constraint Key Description

aID varchar(10) Not Null Primary Author ID

aFName varchar(20) Not Null Author first name

aLName varchar(20) Not Null Author last name

AuthorCatalogue (Multivalue Attribute)


Attribute Type Constraint Key Description

arID* varchar(10) Not Null Foreign Author ID denotes author


who may write more than a
book

aCatID* varchar(10) Not Null Foreign Catalogue ID (multivalues)


which denotes book written
by an author or multiple
authors

Page 8/25
Sunway DIIT Database Fundamental I

4. DATA DICTIONARY (Cont.)

BookCopies
Attribute Type Constraint Key Description

bkID varchar(10) Not Null Primary Book ID

bkStatus varchar(20) Not Null Book rental status (Available,


Rented Out, Under Repair,
etc.)

bkBID* varchar(10) Not Null Foreign Branch ID

bkCatID* varchar(10) Not Null Foreign Catalogue ID

Rental
Attribute Type Constraint Key Description

rID varchar(10) Not Null Primary Rental ID

rDateRented date Not Null Rented date

rDateReturned date Not Null Return date

rBkID* varchar(10) Not Null Foreign Book ID

rCID* varchar(10) Not Null Foreign Customer ID

Page 9/25
Sunway DIIT Database Fundamental I

5. SQL STATEMENTS

5.1 Data Definition Language (DDL)

5.1.1 DDL Codes

create database BookRentalCo;


use BookRentalCo;

create table Branch


(bID varchar(10) primary key,
bName varchar(15) not null unique,
bTel varchar(15) not null,
bLot varchar(7) null,
bStreet varchar(20) null,
bArea varchar(20) not null,
bPostcode int(10) null,
bState varchar(15) not null);

create table Staff


(sID varchar(10) primary key,
sFName varchar(10) not null,
sLName varchar(10) not null,
sPosition varchar(25) not null,
sSalary float(7,2) not null,
sBID varchar(10) not null);

create table Customer


(cID varchar(10) primary key,
cFName varchar(10) not null,
cLName varchar(10) not null,
cLot varchar(5) not null,
cStreet varchar(30) not null,
cArea varchar(30) not null,
cPostcode int(10) not null,
cState varchar(10) not null,
cDateRegistered date not null,
cBID varchar(10) not null);

create table cTel


(cTelID varchar(10) not null,
cTel varchar(15) not null);

create table Book


(catID varchar(10) primary key,

Page 10/25
Sunway DIIT Database Fundamental I

title varchar(40) not null,


type varchar(20) not null,
category varchar(20) not null,
dailyRental float(5,2) not null,
cost float(5,2) not null,
quantityOnHand int(5) not null);

create table Author


(aID varchar(10) primary key,
aFName varchar(20) not null,
aLName varchar(20) not null);

create table AuthorCatalogue


(arID varchar(10) not null,
aCatID varchar(10) not null);

create table BookCopies


(bkID varchar(10) primary key,
bkStatus varchar(20) not null,
bkBID varchar(10) not null,
bkCatID varchar(10) not null);

create table Rental


(rID varchar(10) primary key,
rDateRented date not null,
rDateReturned date not null,
rBKID varchar(10) not null,
rCID varchar(10) not null);

Page 11/25
Sunway DIIT Database Fundamental I

5.1.2 Screenshots of Programs

Figure 3. Table (Branch, Staff)

Page 12/25
Sunway DIIT Database Fundamental I

Figure 4. Table (Customer, cTel, Book)

Page 13/25
Sunway DIIT Database Fundamental I

Figure 5. Table (Author, AuthorCatalogue, BookCopies, Rental)

Page 14/25
Sunway DIIT Database Fundamental I

5. SQL STATEMENTS (Cont.)

5.2 Data Manipulation Language (DML)

5.2.1 DML Codes (Injecting Data Into Tables)

insert into branch values


('B0001', 'Sunway', '+6012 345 6789', 'BK45', 'Jalan Sunway 2A', 'Bandar Sunway', '42100',
'Selangor'),
('B0002', 'Damansara', '+603 578 1113', 'GD67', 'Jalan DH 4B', 'Damansara Heights',
'43000', 'Selangor');

insert into staff values


('S0001', 'Mohammad', 'Nazeem', 'Retail Assistant', '1300', 'B0001'),
('S0002', 'Christina', 'Lim', 'Branch Manager', '5000', 'B0001'),
('S0003', 'Pravin', 'Magadevan', 'Cashier', '1300', 'B0001'),
('S0004', 'Alex', 'Raj', 'Retail Assistant', '1300', 'B0001');

insert into customer values


('C0001', 'Safwan', 'Salim', '74', 'Jalan Taman Muda', 'Taman Muda', '40320', 'Selangor',
'2021-1-21', 'B0001'),
('C0002', 'Navhilan', 'Mohan', '33A', 'Jalan PJS 15/2', 'PJS 15', '40560', 'Selangor',
'2021-4-4', 'B0001'),
('C0003', 'Gloria', 'Lee', '8B', 'Jalan Kampung Baru 4', 'Kampung Baru', '40120', 'Selangor',
'2021-1-19', 'B0001'),
('C0004', 'Rafeeq', 'Ismael', '6B', 'Jalan Kemuning Utama 6', 'Kota Kemuning', '40420',
'Selangor', '2021-8-23', 'B0001'),
('C0005', 'Prasanth', 'Kumar', '9B', 'Jalan Simpang Lima 4', 'Taman Simpang Lima', '41230',
'Selangor', '2021-9-4', 'B0002'),
('C0006', 'Wen Ming', 'Chong', '10B', 'Jalan Kebun 8', 'Kampung Kebun', '42011', 'Selangor',
'2021-8-31', 'B0001'),
('C0007', 'Mohamed', 'Jamel ', '99', 'Jalan Kampung Kapar', 'Kampung Kapar', '50355',
'Perak', '2021-1-21', 'B0001');

insert into cTel values


('C0001','+6016-456-6513'),
('C0002','+6014-538-8753'),
('C0003','+6016-432-3485'),
('C0003','+6014-774-4421'),
('C0004','+6014-536-2432'),
('C0005', '+6017-453-6741'),
('C0006', '+603-464-3982'),
('C0007', '+6014-3234-2342');

insert into book values


('CT0001', 'Love Triangle', 'Novel', 'Romance', '10', '15', '4'),
('CT0002', 'Lost Temple of Ethernity', 'Comic', 'Sci-Fi', '20', '30', '1'),
('CT0003', 'Last Hurrah', 'Novel', 'Contemporary', '24', '32', '2'),
('CT0004', 'What If I Do', 'Comic', 'Children', '40', '45', '1'),
('CT0005', 'Romeo Never Dies', 'Novel', 'Romance', '30', '40', '1'),

Page 15/25
Sunway DIIT Database Fundamental I

('CT0006', 'The Last Dance', 'Novel', 'Sci-Fi', '30', '37', '1'),


('CT0007', 'Till The Day I Die', 'Novel', 'Romance', '30', '34', '1'),
('CT0008', 'Diary Of The Wimpy Kid: The Last Straw', 'Novel', 'Comedy', '30', '35', '1');

insert into author values


('A0001', 'Emily', 'Smith'),
('A0002', 'Samuel', 'Frankowski'),
('A0003', 'Wilson', 'Harrold'),
('A0004', 'Catherine', 'Macaslister'),
('A0005', 'Julius', 'Maddison');

insert into aCatID values


('A0001', 'CT0001'),
('A0001', 'CT0005'),
('A0002', 'CT0001'),
('A0003', 'CT0007'),
('A0004', 'CT0004'),
('A0004', 'CT0008'),
('A0005', 'CT0002'),
('A0005', 'CT0003'),
('A0005', 'CT0006');

insert into bookcopies values


('Bk0001', 'Rented Out', 'B0001', 'CT0001'),
('Bk0002', 'Rented Out', 'B0001', 'CT0001'),
('Bk0003', 'Rented Out', 'B0001', 'CT0001'),
('Bk0004', 'Available', 'B0001', 'CT0001'),
('Bk0005', 'Available', 'B0001', 'CT0002'),
('Bk0006', 'Under Repair', 'B0001', 'CT0003'),
('Bk0007', 'Available', 'B0001', 'CT0004'),
('Bk0008', 'Rented Out', 'B0001', 'CT0007'),
('Bk0009', 'Rented Out', 'B0001', 'CT0003'),
('Bk0010', 'Rented Out', 'B0001', 'CT0005'),
('Bk0011', 'Rented Out', 'B0001', 'CT0006'),
('Bk0012', 'Rented Out', 'B0001', 'CT0008');

insert into rental values


('R0001', '2021-1-24', '2021-2-1', 'Bk0001', 'C0001'),
('R0002', '2021-1-24', '2021-2-1', 'Bk0003', 'C0002'),
('R0003', '2021-1-24', '2021-2-1', 'Bk0008', 'C0003'),
('R0004', '2021-1-29', '2021-2-10', 'Bk0009', 'C0003'),
('R0005', '2021-7-21', '2021-8-1', 'Bk0010', 'C0002');

select * from branch;


select * from staff;
select * from customer;
select * from cTel;
select * from book;
select * from author;
select * from aCatID;
select * from bookcopies;

Page 16/25
Sunway DIIT Database Fundamental I

select * from rental

5.2.2 Screenshots of Programs (Injecting Data Into Tables)

Figure 6. Data injected into Table (Branch, Staff, Customer)

Page 17/25
Sunway DIIT Database Fundamental I

Figure 7. Data injected into Table (cTel, Book, Author)

Page 18/25
Sunway DIIT Database Fundamental I

Figure 8. Data injected into Table (Author, AuthorCatalogue, BookCopies)

Page 19/25
Sunway DIIT Database Fundamental I

5.2.3 DML Codes (Query I)

List all the stock at Sunway branch. The list should consist of book number, title, quantity on
hand, unit price, author’s ID and names.

SELECT
bookcopies.bkID, bkCatID, bkBID, bkStatus,
book.Title, quantityOnHand, Cost,
author.aID, aFName, aLName
FROM
bookcopies
LEFT JOIN book
ON book.catID = bookcopies.bkCatID
LEFT JOIN authorcatalogue
ON bookcopies.bkCatID=authorcatalogue.aCatID
LEFT JOIN author
ON author.aID = authorcatalogue.arID;

5.2.4 Screenshots of Programs (Query I)

Figure 9. Query I Output

Note: 1. The list returns multiple rows due to the presence of co-authors.
2. B0001 is Sunway branch.
3. Cost = Unit Price of book.

Page 20/25
Sunway DIIT Database Fundamental I

5.2.5 DML Codes (Query II)

List all the rental of January 2021. The list should consist of member number, member
name, rental number, book number, title, date out, date returned and daily rental.

SELECT
rental.rID, rBkID, rDateRented, rDateReturned,
book.title, dailyRental,
customer.cID, cFName, cLName
FROM
customer
LEFT JOIN rental
ON customer.cID = rental.rCID
LEFT JOIN bookcopies
ON bookcopies.bkID = rental.rBkID
LEFT JOIN book
ON book.catID = bookcopies.bkCatID
WHERE MONTH (rDateRented)= '1';

5.2.6 Screenshots of Programs (Query II)

Figure 10. Query II Output

Page 21/25
Sunway DIIT Database Fundamental I

5.2.7 DML Codes (Query III)


List all the author details and number of books written by each of them.

SELECT
author.aFName, aLName,
authorCatalogue.*,
book.Title
FROM
book
INNER JOIN authorCatalogue
ON book.catID = authorCatalogue.aCatID
INNER JOIN author
ON author.aID = authorcatalogue.arID;

5.2.8 Screenshots of Programs (Query III)

Figure 11. Query III Output

Page 22/25
Sunway DIIT Database Fundamental I

5.2.9 DML Codes (Query IV)


List all the member details who did not rent any book with Comics and Novels Rental
Company.

SELECT
customer.cID, cFName, cLName,
rental.*
FROM
customer
LEFT JOIN rental
ON customer.cID = rental.rCID
WHERE rental.rID is null;

5.2.10 Screenshots of Programs (Query IV)

Figure 12. Query IV Output

Page 23/25
Sunway DIIT Database Fundamental I

5.2.11 DML Codes (Query V)

List all the book details that had been rented by Gloria in January 2021.

SELECT
customer.cID, cFName, cLName,
book.title,
bookcopies.bkID, bkStatus,
rental.rID, rDateRented
FROM
customer
LEFT JOIN rental
ON customer.cID = rental.rCID
LEFT JOIN bookcopies
ON bookcopies.bkID = rental.rBkID
LEFT JOIN book
ON book.catID = bookcopies.bkCatID
WHERE customer.cFName = 'Gloria' and MONTH (rDateRented) = '1';

5.2.12 Screenshots of Programs (Query V)

Figure 13. Query V Output

Page 24/25
Sunway DIIT Database Fundamental I

6. CONCLUSION

In conclusion, databases make lives a little easier. We learned a lot from completing this
assignment but there is much room for areas of development. Database helps us to maintain
information and data, it is a very efficient if not the best mechanism to store and organize data
for many companies. It allows for a centralized system that can easily be modified anywhere
and anytime, it also allows for convenient sharing among multiple users. Another reason why
databases are so crucial is so that companies can keep up with the massive amounts of
information in a singular place. Furthermore, It is also very easy to understand databases
making it accessible to all new users.

Page 25/25

You might also like