Professional Documents
Culture Documents
Assessment 2
Assessment 2
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
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
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
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)
);
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);
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