You are on page 1of 6

NUMBER 1

To answer Question 1, we need to identify and transform the partial


dependencies and transitive dependencies in the given table into
normalized tables.

i. Identifying partial dependencies and transforming into tables in 2nd


Normal Form:

Based on the given table "Invoices (InvoiceNo, ProductNo, SaleDate,


ProductDescription, VendorCode, VendorName, QuantitySold,
ProductPrice)," we can identify the partial dependencies.

Partial dependencies:
- InvoiceNo → SaleDate, VendorCode, VendorName
- ProductNo → ProductDescription, ProductPrice

To transform these partial dependencies into 2nd Normal Form (2NF),


we can create two new tables:

Table 1: Invoices (InvoiceNo [PK], SaleDate, VendorCode [FK],


VendorName [FK])
Table 2: Products (ProductNo [PK], ProductDescription, ProductPrice)

ii. Identifying transitive dependencies and transforming into tables in 3rd


Normal Form:

Based on the current tables obtained from 2NF, we can identify the
transitive dependencies.

Transitive dependency:
- VendorCode → VendorName

To transform this transitive dependency into 3rd Normal Form (3NF), we


can create a new table:

Table 3: Vendors (VendorCode [PK], VendorName)


The final normalized tables in 3NF would be:
Table 1: Invoices (InvoiceNo [PK], SaleDate, VendorCode [FK])
Table 2: Products (ProductNo [PK], ProductDescription, ProductPrice)
Table 3: Vendors (VendorCode [PK], VendorName)

[PK] denotes the primary key, and [FK] denotes the foreign key.

NUMBER 2

(a) CREATE DATABASE Cross_Border_Trucks;

b...

CREATE TABLE tblTruckOwners ( OwnerID INT PRIMARY KEY, OwnerLastName


VARCHAR(50), OwnerFirstName VARCHAR(50), Address VARCHAR(100));

-- Populating tblTruckOwners tableINSERT INTO tblTruckOwners (OwnerID,


OwnerLastName, OwnerFirstName, Address)VALUES (01, 'Ndlovu',
'Giveson', 'Khami Road, Bulawayo'), (02, 'Ndoro', 'Tanaka', 'Wadzanai
Drive, Shamva'), (15, 'Mabgwe', 'Casper', 'Dulibadzimu, Beitbridge'),
(50, 'Titus', 'Lazarus', 'Chikanga, Mutare'), (21, 'Mandhela',
'Ramos', 'Rodeen, Masvingo');-- Creating tblTruckBookings tableCREATE
TABLE tblTruckBookings ( OwnerID INT, Budget INT, TruckDesired
VARCHAR(50));

tblTruckBookings

CREATE TABLE tblTruckBookings ( OwnerID INT, Budget INT,


TruckDesired VARCHAR(50));

-- Populating tblTruckBookings tableINSERT INTO tblTruckBookings


(OwnerID, Budget, TruckDesired)VALUES (02, 3000, 'Iveco'), (02, 3500,
'Benz'), (21, 1300, 'ISUZU'), (50, 7500, 'DAF');

tblTrucks
CREATE TABLE tblTrucks ( SellerID INT, BuyerID INT, Truck
VARCHAR(50));

-- Populating tblTrucks table


INSERT INTO tblTrucks (SellerID, BuyerID, Truck)VALUES (01, 50,
'Iveco'), (02, 15, 'DAF'), (50, 01, 'ISUZU'), (21, 02, 'Benz');

C. …..a query that retrieves the Last Names and the Addresses of
all owners whose last names start with “M” or owners who live in
Shamva
SELECT OwnerLastName, AddressFROM tblTruckOwnersWHERE OwnerLastName

LIKE 'M%' OR Address LIKE '%Shamva%';

d a query that calculates the sum, average, minimum and


maximum of the budgets set out for the trucks.

SELECT SUM(Budget) AS TotalBudget, AVG(Budget) AS AverageBudget,


MIN(Budget) AS MinimumBudget, MAX(Budget) AS MaximumBudgetFROM
tblTruckBookings;
e.… a query that retrieves the First Names, Last Names
and Truck for all ISUZU truck owners

SELECT OwnerFirstName, OwnerLastName, TruckFROM tblTruckOwnersJOIN


tblTruckBookings ON tblTruckOwners.OwnerID =
tblTruckBookings.OwnerIDJOIN tblTrucks ON tblTruckOwners.OwnerID =
tblTrucks.SellerIDWHERE Truck = 'ISUZU'ORDER BY OwnerLastName DESC;

You might also like