Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

Student ID’s

KAINAT 59289
HAMZA FARID 59233
SAROJ GAUTAM 59702
Video Link
https://drive.google.com/file/d/1aq-
QWoZ7a2loYNPqp2JN9KLfDh4wEMXG/view?usp=drivesdk
Activity 1: Normalization
Table 1
Frist Normal Form (1NF)
Supplier Supplier Product Product Cost Markup Price Department
ID Name ID Name (AUD) (AUD)

Fresh Vegetarian
D23 7601 Carrots 4.77 7% 4.90
Fruits Product
D23 Fresh 7601 Cucumbe 4.77 7% 4.90 Vegetarian
Fruits rs Product
B39 Adam 4325 Lamb 7.47 12% 7.99 Meat
Adrain Chops
B39 Adam 5434 Boneless 9.01 12% 10.58 Butcher
Adrain
V39 Gourmet 2333 Orange 3.80 7% 3.58 Frozen

Second Normal Form (2NF)


Table 1: Suppliers
Supplier ID Supplier Name
D23 Fresh Fruits
B39 Adam Adrain
V39 Gourmet
Table 2: Products
Supplier Product Product Cost Marku Price
ID Code Description (AUD) p (AUD) Department
D23 7601 carrots, 4.77 7% 5.10 Vegetarian
cucumbers product
B39 4325 lamb chops 7.47 12% 8.36 Meat
B39 5434 boneless 9.01 12% 10.09 Butcher
V39 2333 orange 3.80 7% 4.07 Frozen

Third Normalization Form (3NF)


Table 1: Suppliers
Supplier ID Supplier Name
D23 Fresh Fruits
B39 Adam Adrain
V39 Gourmet

Table 2: Products
Product ID Product Name Supplier ID Cost (AUD) Markup Price (AUD)
7601 Carrots D23 4.77 7% 4.90
7601 Cucumbers D23 4.77 7% 4.90
4325 Lamb Chops B39 7.47 12% 7.99
5434 Boneless (Meat?) V39 9.01 12% 10.58
2333 Orange D23 3.80 7% 3.58

Table 3: Departments
Product ID Department
7601 Vegetarian Product
4325 Meat
5434 Butcher
2333 Frozen
Bed Drug Mode of Units
Patient Patient Ward Numb Drug Descr Administra per Start Finish Doctor
ID Name Name er Code Drug Name iption Dosage tion Day Date Date ID
MNR4 Matthe General B66 AX304 Amoxicillin Antib 0.5mg/ IV 2 18/02 20/02/ SN567
567 w Ward iotic ml /2022 2022
Walsh
MNR4 Matthe General B66 AX504 Aceclofenac Pain 5mg/ml IV 5 28/02 28/02/ SN567
567 w Ward Killer /2022 2022
Walsh
MNR4 Matthe General B66 AX304 Amoxicillin Antib 1mg/ml Oral 2 22/02 24/02/ SN567
567 w Ward iotic /2022 2022
Walsh
MNR4 Matthe General B66 AX900 Aceclofenac Pain 5mg/ml IV 7 28/02 06/03/ SN567
567 w Ward Killer /2022 2022
Walsh

Table 2: Patient Medication History


Frist Normal Form (1NF)
Second Normal Form (2NF)
Normalized Tables:
Patient Info
MNR Patient Name Ward Name Room Number Bed Number Doctor ID
4567 Matthew Walsh General Ward B66 25 SN567

Treatment Info

MNR Start Date Drug Code Dosage MoA Units/Day Finish Date
4567 18/02/2022 AX304 0.5mg/ml IV 2 20/02/2022
4567 28/02/2022 AX504 5mg/ml IV 5 28/02/2022
4567 22/02/2022 AX304 1mg/ml Oral 2 24/02/2022
4567 28/02/2022 AX900 5mg/ml IV 7 06/03/2022
Drug Info

Drug Code Drug Name Drug Description


AX304 Amoxicillin Antibiotic
AX504 Aceclofenac Pain Killer
AX900 Aceclofenac Pain killer

Third Normal Form (3NF)


To satisfy 3NF, a table must first meet all the criteria of 2NF, plus:

1. No transitive dependencies: No non-primary key column should depend on another


non-primary key column.

3NF Refinement:

• Split attributes in Medication Table that are about the drug itself from those that are
specific to the patient's treatment.
• Establish reference tables for drugs and doctors if information repeats or is derived.

3NF Tables:

1. Patient Table
o Patient ID (Primary Key)
o Ward Name
o Bed Number
2. Doctor Table
o Doctor ID (Primary Key)
o Doctor Name
3. Drug Table
o Drug Code (Primary Key)
o Drug Name
o Drug Description
4. Prescription Table
o Patient ID
o Drug Code
o Doctor ID
o Start Date (Part of Composite Primary Key)
o Finish Date
o Dosage
o MoA
o Units/Day

Activity 2:
Part A:
Queries for Creating Tables:
For Customers Table:
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
FName VARCHAR(100),
LName VARCHAR(100),
Street VARCHAR(255),
Town VARCHAR(100),
State VARCHAR(50),
Postcode VARCHAR(20),
Balance DECIMAL(10, 2)
);

For Videos Table:


CREATE TABLE Videos (
SSNV BIGINT PRIMARY KEY,
Name VARCHAR(255),
VideoMaker VARCHAR(255),
Year INT,
Cost DECIMAL(10, 2),
ChargeCode INT,
FOREIGN KEY (ChargeCode) REFERENCES Charge(ChargeCode)
);

For Rent Table:


CREATE TABLE Rent (
RentID INT PRIMARY KEY,
RentDate DATE,
CustomerID INT,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);

For Rent Details Table:


CREATE TABLE RentDetails (
RentID INT,
VideoCopy INT,
RentFee DECIMAL(10, 2),
DueDate DATE,
ReturnDate DATE,
LateFee DECIMAL(10, 2),
PRIMARY KEY (RentID, VideoCopy),
FOREIGN KEY (RentID) REFERENCES Rent(RentID),
FOREIGN KEY (VideoCopy) REFERENCES VideoCopy(VideoCopy_Num)
);

For Video Copy Table:


CREATE TABLE VideoCopy (
VideoCopy_Num INT PRIMARY KEY,
VideoCopy_ArrivalDate DATE,
SSNV BIGINT,
FOREIGN KEY (SSNV) REFERENCES Videos(SSNV)
);

For Charge Table:


CREATE TABLE Charge (
ChargeCode INT PRIMARY KEY,
Description VARCHAR(255),
RentFee DECIMAL(10, 2),
DailyLateFee DECIMAL(10, 2)
);
Part B:
Quires for Inserting Data
From Table 1 Customers:

INSERT INTO Customers (CustomerID, FName, LName, Street, Town, State, Postcode,
Balance) VALUES
(211, 'Rose', 'Green', '2 Alison St', 'Randwick', 'NSW', '2030', 100),
(212, 'Stacey', 'Knell', '50 Garden St', 'Revesbay', 'NSW', '2140', 50),
(213, 'India', 'Elmore', '44 Main St', 'Botany', 'NSW', '2332', 15),
(214, 'Cameron', 'Rosere', '73 Everlast St', 'Geelong', 'VIC', '3754', 0),
(215, 'John', 'Parker', '43 Cook Ave.', 'Parkwood', 'NSW', '2543', 12),
(216, 'Robert', 'Swarm', '71 Vase St', 'Revesbay', 'NSW', '2140', 75),
(217, 'Louis', 'Opral', '34 East Drive', 'Corio', 'VIC', '3125', 33),
(218, 'Grace', 'Knen', '9 Max Avenue', 'Highton', 'VIC', '3453', 22),
(219, 'Wendy', 'David', '3 Elmore St', 'Botany', 'NSW', '2332', 25),
(220, 'Kim', 'Green', '87 Kent St', 'Randwick', 'NSW', '2030', 34);

From Table 2 Rent:


INSERT INTO Rent (RentID, RentDate, CustomerID) VALUES
(7001, '2020-05-01', 213),
(7002, '2020-07-02', 219),
(7003, '2021-02-01', 212),
(7004, '2021-02-01', 213),
(7005, '2021-02-01', 220);

From Table 3 Rent Details:


INSERT INTO RentDetails (RentID, VideoCopy, RentFee, DueDate, ReturnDate, LateFee)
VALUES
(7001, 4325, 5, '2020-05-30', '2020-05-29', NULL),
(7001, 5432, 7, '2020-05-30', '2020-05-30', NULL),
(7002, 4329, 4.5, '2020-09-02', '2020-08-28', NULL),
(7003, 4327, 3.5, '2021-04-01', '2021-03-29', NULL),
(7003, 6637, 10, '2021-04-01', '2021-03-29', NULL),
(7003, 6634, 6, '2021-04-01', '2021-04-01', NULL),
(7004, 4326, 5, '2021-04-01', '2021-04-01', NULL),
(7004, 4328, 12, '2021-04-01', NULL, NULL), -- ReturnDate and LateFee are NULL
(7005, 5433, 3.5, '2021-05-07', NULL, NULL), -- ReturnDate and LateFee are NULL
(7004, 6635, 10, '2021-04-01', '2021-04-01', NULL);

From Table 4 Charge:


INSERT INTO Charge (ChargeCode, Description, RentFee, DailyLateFee) VALUES
(1, 'Standard', 5, 2),
(2, 'New', 10, 4),
(3, 'Discount', 2, 0.5);

From Table 5 VideoCopy:


INSERT INTO VideoCopy (VideoCopy_Num, VideoCopy_ArrivalDate, SSNV) VALUES
(4325, '2019-01-10', 1337627909),
(4326, '2019-01-10', 1337627909),
(4327, '2019-01-10', 1337627909),
(4328, '2019-02-12', 0241258766),
(4329, '2019-02-12', 0241258766),
(5432, '2019-04-16', 1292166622),
(5433, '2019-04-16', 1292166622),
(5434, '2019-04-16', 1292166622),
(5435, '2019-04-16', 1292166622),
(6634, '2019-06-28', 0137081073),
(6635, '2019-06-28', 0137081073),
(6636, '2019-06-28', 9780134085),
(6637, '2019-06-28', 9780134085);

From Table 6 Videos:


INSERT INTO Videos (SSNV, Name, VideoMaker, Year, Cost, ChargeCode) VALUES
(1337627909, 'Oracle Implementation Video', 'Steven Charles', 2018, 116, 1),
(0241258766, 'Learning from Data Video', 'Daniel Whitener', 2020, 17, 1),
(1292166622, 'The Practice of Computing Using Python Video', 'Richard Murphy', 2016, 95, 2),
(0137081073, 'C++ Programming Video', 'Robert Adam', 2011, 49, 3),
(9780134085, 'Security in Computing Video', 'John petter', 2015, 100, 1);

Part C:
Queries to Perform Tasks:
1. To list all the videos where the cost of the video is between 50 and 75.
SELECT *
FROM Videos
WHERE Cost BETWEEN 50 AND 75;

2. To list the details of all customers last names that begin with the letters ‘Kne’
SELECT *
FROM Customers
WHERE LName LIKE 'Kne%';

3. To list the customer id, first name, last name, state and total number of videos
borrowed by the customer.
SELECT
c.CustomerID,
c.FName,
c.LName,
c.State,
COUNT(rd.VideoCopy) AS TotalVideosBorrowed
FROM
Customers c
JOIN
Rent r ON c.CustomerID = r.CustomerID
JOIN
RentDetails rd ON r.RentID = rd.RentID
GROUP BY
c.CustomerID,
c.FName,
c.LName,
c.State;

4. To list each customer first name, last name, the rented video name and due date.
SELECT
c.FName AS FirstName,
c.LName AS LastName,
v.Name AS VideoName,
rd.DueDate
FROM
Customers c
JOIN
Rent r ON c.CustomerID = r.CustomerID
JOIN
RentDetails rd ON r.RentID = rd.RentID
JOIN
VideoCopy vc ON rd.VideoCopy = vc.VideoCopy_Num
JOIN
Videos v ON vc.SSNV = v.SSNV

5. To create a view “BorrowDetails” for the query used in previous question and also
display the number of videos each customer has from the newly created view.
Step 1: First Create a View:
CREATE VIEW BorrowDetails AS
SELECT
c.CustomerID,
c.FName AS FirstName,
c.LName AS LastName,
v.Name AS VideoName,
rd.DueDate
FROM
Customers c
JOIN
Rent r ON c.CustomerID = r.CustomerID
JOIN
RentDetails rd ON r.RentID = rd.RentID
JOIN
VideoCopy vc ON rd.VideoCopy = vc.VideoCopy_Num
JOIN
Videos v ON vc.SSNV = v.SSNV;
Step 2:
SELECT
CustomerID,
FirstName,
LastName,
COUNT(VideoName) AS NumberOfVideos
FROM
BorrowDetails
GROUP BY
CustomerID, FirstName, LastName;
Refrences;
[1] S. Ravikiran, “Understanding The Difference Between SQL And MySQL,” Simplilearn.com,
Apr. 27, 2021. https://www.simplilearn.com/tutorials/sql-tutorial/difference-between-sql-and-
mysql
[2] Watt and N. Eng, “Chapter 15 SQL Structured Query Language,” Opentextbc.ca, Oct. 24,
2014. https://opentextbc.ca/dbdesign01/chapter/sql-structured-query-language/
[3] E. EESSAAR, “(PDF) The Database Normalization Theory and the Theory of Normalized
Systems: Finding a Common Ground,” ResearchGate, 2016.
https://www.researchgate.net/publication/297731569_The_Database_Normalization_Theory_an
d_the_Theory_of_Normalized_Systems_Finding_a_Common_Ground

You might also like