0% found this document useful (0 votes)
10 views18 pages

CSC 313 Manual Solution by Code AJ

The document consists of multiple laboratory exercises focusing on SQL queries, relational algebra, and ER diagram creation in MySQL Workbench. It includes tasks such as retrieving client and product information, updating records, and creating relationships between entities. Additionally, it provides a step-by-step guide for modeling a company database and verifying the database structure and data integrity.

Uploaded by

nasiribrahim062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views18 pages

CSC 313 Manual Solution by Code AJ

The document consists of multiple laboratory exercises focusing on SQL queries, relational algebra, and ER diagram creation in MySQL Workbench. It includes tasks such as retrieving client and product information, updating records, and creating relationships between entities. Additionally, it provides a step-by-step guide for modeling a company database and verifying the database structure and data integrity.

Uploaded by

nasiribrahim062
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Laboratory Exercise #1

1. Find out the names of the clients

SELECT name FROM client_master;

2. Retrieve the names and cities of all the clients

SELECT name, city FROM client_master;

3. List the various products available from the product_master table

SELECT description FROM product_master;

4. List all the clients who are located in Kaduna

SELECT * FROM client_master WHERE city = 'Kaduna';

5. Display the information for client no. 0001 and 0002

SELECT * FROM client_master WHERE client_no IN ('0001', '0002');

6. Find all the products whose description is ‘1.44 Drive’ and ‘1.22 Drive’

SELECT * FROM product_master WHERE description IN ('1.44 Drive', '1.22 Drive');

7. Find all the products whose sell price is greater than 5000

SELECT * FROM product_master WHERE sell_price > 5000;

8. Find the list of all clients who stay in the city ‘Kaduna’ or city ‘Jos’ or city ‘Kashere’

SELECT * FROM client_master WHERE city IN ('Kaduna', 'Jos', 'Kashere');

9. Find the product whose selling price is greater than 2000 and less than or equal to 5000

SELECT * FROM product_master WHERE sell_price > 2000 AND sell_price <= 5000;

10. List the name, city, and state of clients not in the state of ‘Kaduna’

SELECT name, city, state FROM client_master WHERE state <> 'Kaduna';

Laboratory Exercise #2

1. Change the selling price of ‘1.44 floppy drive’ to ₦1150.00


UPDATE product_master
SET sell_price = 1150.00
WHERE description = '1.44 floppies';

2. Delete the record with client no '0001' from the client_master relation
DELETE FROM client_master
WHERE client_no = '0001';

3. Change the city of client_no '0005' to ‘FCT’


UPDATE client_master
SET city = 'FCT'
WHERE client_no = '0005';

4. Find out the clients who stay in a city whose second letter is 'a'

SELECT * FROM client_master


WHERE city LIKE '_a%';

5. List the products in sorted order of their description

SELECT * FROM product_master


ORDER BY description ASC;

6. Count the total number of orders

(Assuming each row in product_master represents an order.)


SELECT COUNT(*) AS total_orders FROM product_master;

7. Calculate the average price of all the products


SELECT AVG(sell_price) AS average_price FROM product_master;

8. Determine the maximum and minimum prices. Rename the title as max price and min
price respectively

SELECT
MAX(sell_price) AS max_price,
MIN(sell_price) AS min_price
FROM product_master

Laboratory Exercise #3

1. Relational Algebra Expressions

(a) All information about all projects

Relational Algebra:
πprojlD, name, city (projects)

SQL Equivalent:
SELECT * FROM projects;

(b) All information about all projects in London

Relational Algebra:
σcity='London'

SQL Equivalent:
SELECT * FROM projects
WHERE city = 'London';

(c) The supplier numbers of the suppliers that deliver to project number 123

Relational Algebra:
πsupplID(σprojID=123(deliveries))

SQL Equivalent:
SELECT DISTINCT supplID FROM deliveries
WHERE projID = 123;

(d) The product numbers of products that are delivered by suppliers in London

Relational Algebra:
πprodNbr(σcity='London' (suppliers) ⋈ deliveries)

SQL Equivalent:
SELECT DISTINCT deliveries.prodNbr
FROM deliveries
JOIN suppliers ON deliveries.supplID = suppliers.supplID
WHERE suppliers.city = 'London';

(e) All pairs of product numbers such that at least one supplier delivers both products

Relational Algebra:
πD1.prodNbr, D2.prodNbr (σD1.supplID = D2.supplID ^ D1.prodNbr ≠ D2.prodNbr(ρ
D1(deliveries) × ρD2(deliveries)))

SQL Equivalent:
SELECT DISTINCT D1.prodNbr, D2.prodNbr
FROM deliveries D1, deliveries D2
WHERE D1.supplID = D2.supplID AND D1.prodNbr <> D2.prodNbr;
Laboratory Exercise #4

a.​ SELECT fName, lName FROM Students;


b.​ SELECT fName, lName FROM Students ORDER BY lName, fName;
c.​ SELECT COUNT(*) AS total_students FROM Students;
d.​ SELECT * FROM Courses WHERE courseCode LIKE 'CSC%';
e.​ SELECT * FROM Courses WHERE creditHours > 3;
f.​ SELECT level, COUNT(*) AS course_count FROM Courses GROUP BY level;
g.​ SELECT courseCode FROM TakenCourses WHERE matricNo = '203400501';
h.​ SELECT Courses.courseName, Courses.creditHours ​
FROM Courses ​
JOIN TakenCourses ON Courses.courseCode = TakenCourses.courseCode​
WHERE TakenCourses.matricNo = '203400501';
i.​ SELECT SUM(Courses.creditHours) AS total_credit_hours ​
FROM Courses ​
JOIN TakenCourses ON Courses.courseCode = TakenCourses.courseCode​
WHERE TakenCourses.matricNo = '203400501';
j.​ SELECT matricNo, AVG(
CASE grade
WHEN 'A' THEN 5
WHEN 'B' THEN 4
WHEN 'C' THEN 3
WHEN 'D' THEN 2
WHEN 'E' THEN 1
WHEN 'F' THEN 0
END) AS grade_average
FROM TakenCourses
WHERE matricNo = '203400501'
GROUP BY matricNo;
k.​ WITH StudentAverages AS (
SELECT matricNo, AVG(
CASE grade
WHEN 'A' THEN 5
WHEN 'B' THEN 4
WHEN 'C' THEN 3
WHEN 'D' THEN 2
WHEN 'E' THEN 1
WHEN 'F' THEN 0
END) AS grade_average
FROM TakenCourses
GROUP BY matricNo
)
SELECT Students.matricNo, Students.fName, Students.lName,
StudentAverages.grade_average
FROM Students
JOIN StudentAverages ON Students.matricNo = StudentAverages.matricNo
WHERE StudentAverages.grade_average = (SELECT MAX(grade_average) FROM
StudentAverages);

Laboratory Exercise #5

Step-by-Step Guide to Drawing the Company ER Diagram in MySQL Workbench

Step 1: Open MySQL Workbench

1.​ Launch MySQL Workbench


○​ Find MySQL Workbench on your computer and open it.
2.​ Go to Data Modeling Tool
○​ On the home screen, click on "Database" in the top menu.
○​ Select "Model" > "Create New Model" from the dropdown.
○​ This will open a new blank workspace for creating the ER diagram.

Step 2: Create a New ER Diagram

1.​ Open the EER Diagram Editor


○​ Click on the "Add Diagram" button (a plus sign in the "EER Diagrams"
section).
○​ A blank canvas will open, where you can start adding tables and
relationships.

Step 3: Create Entities (Tables)

A. Create EMPLOYEE Table

1.​ On the toolbar, click on the Table icon (looks like a small table).
2.​ Click anywhere on the blank workspace to place a new table.
3.​ Rename the table:
○​ Double-click the table name (default is "table1").
○​ Change it to "EMPLOYEE".
4.​ Define Attributes (Columns)
○​ Click on the Columns tab.
○​ Add the following columns:
5.​
Column Name Data Type Primary Key Not Null

Emp_ID INT Yes (PK) Yes


Name VARCHAR(50) No Yes

Salary DECIMAL(10,2) No Yes

Address VARCHAR(100) No Yes

Sex CHAR(1) No Yes

Birth_Date DATE No Yes

○​ Click Apply, then Close.

B. Create DEPARTMENT Table

1.​ Click on the Table icon again.


2.​ Place a new table and rename it to "DEPARTMENT".
3.​ Go to the Columns tab and add the following:
Column Name Data Type Primary Key Not Null

Dept_ID INT Yes (PK) Yes

Name VARCHAR(50) No Yes

Location VARCHAR(100) No Yes

○​ Click Apply, then Close.

C. Create PROJECT Table

1.​ Add a new table and rename it "PROJECT".


2.​ Go to the Columns tab and add:
Column Name Data Type Primary Key Not Null

Proj_ID INT Yes (PK) Yes

Name VARCHAR(50) No Yes

Start_Date DATE No Yes

○​ Click Apply, then Close.

D. Create WORKS_FOR Table (Many-to-One Relationship)


1.​ Add a new table and rename it "WORKS_FOR".
2.​ Go to the Columns tab and add:
Column Name Data Type Primary Key Not Null Foreign Key

Emp_ID INT Yes (PK) Yes Yes (EMPLOYEE)

Dept_ID INT Yes (PK) Yes Yes (DEPARTMENT)

3.​ ​
Set Foreign Keys:
○​ Click on the Foreign Keys tab.
○​ Click Add, then:
■​ For Emp_ID, set the reference table to EMPLOYEE.
■​ For Dept_ID, set the reference table to DEPARTMENT.
○​ Click Apply, then Close.

E. Create WORKS_ON Table (Many-to-Many Relationship)

1.​ Add a new table and rename it "WORKS_ON".


2.​ Go to the Columns tab and add:
Column Name Data Type Primary Key Not Null Foreign Key

Emp_ID INT Yes (PK) Yes Yes (EMPLOYEE)

Proj_ID INT Yes (PK) Yes Yes (PROJECT)

Hours DECIMAL(5,2) No No No

3.​ ​
Set Foreign Keys:
○​ Click on the Foreign Keys tab.
○​ Click Add, then:
■​ For Emp_ID, set the reference table to EMPLOYEE.
■​ For Proj_ID, set the reference table to PROJECT.
○​ Click Apply, then Close.

F. Create DEPENDENT Table

1.​ Add a new table and rename it "DEPENDENT".


2.​ Go to the Columns tab and add:
Column Name Data Type Primary Key Not Null Foreign Key

Emp_ID INT Yes (PK) Yes Yes (EMPLOYEE)


Dependent_Nam VARCHAR(50) Yes (PK) Yes No
e

Relationship VARCHAR(50) No Yes No

Birth_Date DATE No Yes No

3.​ ​
Set Foreign Keys:
○​ Click on the Foreign Keys tab.
○​ Click Add, then:
■​ For Emp_ID, set the reference table to EMPLOYEE.
○​ Click Apply, then Close.

Step 4: Connect Entities with Relationships

1.​ Click on the One-to-Many Relationship Tool (looks like a line with a crow’s foot).
2.​ Connect:
○​ WORKS_FOR.Emp_ID → EMPLOYEE.Emp_ID
○​ WORKS_FOR.Dept_ID → DEPARTMENT.Dept_ID
○​ WORKS_ON.Emp_ID → EMPLOYEE.Emp_ID
○​ WORKS_ON.Proj_ID → PROJECT.Proj_ID
○​ DEPENDENT.Emp_ID → EMPLOYEE.Emp_ID

Step 5: Save and Export

1.​ Save the Diagram


○​ Click on File > Save Model As.
○​ Save it as company_er_model.mwb.
2.​ Export as an Image
○​ Click on File > Export > Export as PNG.
○​ Save the file as company_er_diagram.png.

Laboratory Exercise #6

Step 1: Open MySQL Workbench and Create a New Model

1.​ Launch MySQL Workbench on your computer.


2.​ Click on "Database" → "New Model" from the top menu.
3.​ A new model window will open. Click on "File" → "Save Model As" and save it with
a relevant name (e.g., Auction_DB.mwb).
Step 2: Create the Entities (Tables)

1.​ On the left panel, click on "EER Diagram" under Model Overview.
2.​ Click on the "Add Table" button (a table icon) from the toolbar at the top.
3.​ Click anywhere on the canvas to create a new table.
4.​ A Table Properties window will appear. Do the following:
○​ Enter the Table Name (e.g., Member).
○​ Under the Columns tab, enter attributes:
■​ Example for Member table:
■​ MemberID (INT, PRIMARY KEY, NOT NULL, Auto Increment)
■​ Name (VARCHAR(100), NOT NULL)
■​ Email (VARCHAR(100), NOT NULL, UNIQUE)
■​ Password (VARCHAR(100), NOT NULL)
■​ HomeAddress (TEXT, NULL)
■​ PhoneNumber (VARCHAR(20), NULL)
○​ Click Apply → Apply Changes → Close.
5.​ Repeat steps 2-4 for each entity (Buyer, Seller, Item, Bid, Transaction, Feedback,
and Category) using the attributes provided in the relational schema.

Step 3: Create Relationships Between Entities

1.​ Click on the "One-to-Many" relationship tool (crow's foot icon) from the toolbar.
2.​ Connect related tables:
○​ Example: Member → Buyer
■​ Click on Member and then click on Buyer to create a 1-to-1
relationship.
○​ Example: Member → Seller (1-to-1).
○​ Example: Seller → Item (1-to-many).
○​ Example: Item → Bid (1-to-many).
○​ Example: Bid → Transaction (1-to-1).
○​ Example: Transaction → Feedback (1-to-many).
○​ Example: Category → Item (1-to-many).
3.​ Once connected, double-click the relationship line and:
○​ Set Foreign Keys correctly (Example: Item.SellerID →
Seller.MemberID).
○​ Click Apply.

Step 4: Generate SQL Schema from ER Diagram

1.​ Go to "File" → "Export" → "Forward Engineer SQL CREATE Script".


2.​ Select your database name and click Next.
3.​ In the options, select all tables and relationships to be included in the schema.
4.​ Click Next → Export to File (or Copy the SQL code to clipboard).
5.​ Click Finish.

Step 5: Execute the SQL Schema in MySQL Server


1.​ Open MySQL Workbench and connect to your MySQL server.
2.​ Click on the "SQL Editor" tab.


3.​ Paste the generated SQL code in the query window.
4.​ Click Execute ( ) to create the tables in your database.

Step 6: Insert Sample Data (Optional)

After creating the tables, you can add sample data using the following SQL:

INSERT INTO Member (MemberID, Name, Email, Password, HomeAddress,


PhoneNumber)
VALUES (1, 'John Doe', '[email protected]', 'password123', '123
Street, NY', '1234567890');

INSERT INTO Seller (MemberID, BankAccount, RoutingNumber)


VALUES (1, '12345678', '987654321');

INSERT INTO Item (ItemID, Title, Description, StartBidPrice,


BiddingIncrement, StartDate, EndDate, SellerID)
VALUES (1, 'Laptop', 'Dell XPS 13', 500.00, 10.00, '2025-02-14',
'2025-02-21', 1);

Step 7: Verify the Database

1.​ Run SHOW TABLES; to check all tables.


2.​ Run SELECT * FROM Member; to see inserted data.
3.​ Start running queries to test relationships (e.g., joining Buyer and Bid tables).

Laboratory Exercise #7

Task 1: Finding Keys in Relation R(A, B, C, D, E)

Given Functional Dependencies (FDs):

1.​ A→C
2.​ B→D
3.​ AC → D
4.​ CD → E
5.​ E→A

Step 1: Compute the Closure of Attribute Combinations

To find candidate keys, we compute closures of attribute sets until we find a set that includes
all attributes {A, B, C, D, E}.
Closure of A:

A → C​
E → A (E implies A)​
Since we don't get all attributes, A alone is not a key.

Closure of B:

B → D​
Does not cover all attributes.

Closure of AC:

AC → D​
CD → E (Since we now have C and D)​
E → A (E gives A)

Closure of {A, C} = {A, C, D, E} (Missing B) → Not a key.

Closure of B and any combination:

✅ (All attributes included)


●​ Closure of B alone: {B, D}
●​ Closure of B and A: {A, B, C, D, E}

Candidate Key: AB

Since AB determines all attributes, it is the only candidate key.

Task 2: Keys and BCNF Normalization for Relation R(A, B, C, D)

Given Functional Dependencies:

1.​ D → AC
2.​ A → B
3.​ B → C

Step 1: Compute the Closure of D

D → AC​
A → B​
B→C

So, D⁺ = {A, B, C, D}, which includes all attributes.

Candidate Key: D (since D determines all attributes)

Step 2: Checking for BCNF and 3NF


Checking BCNF:

A relation is in BCNF if every functional dependency X → Y has either:

1.​ X as a superkey OR


2.​ Y is a subset of X (trivial dependency)


●​ D → AC: D is a superkey (BCNF)


●​ A → B: A is NOT a superkey (Not BCNF)
●​ B → C: B is NOT a superkey (Not BCNF)

Since there are dependencies where the left side is not a superkey, R is NOT in BCNF.

Checking 3NF:

A relation is in 3NF if for every dependency X → Y, either:

1.​ X is a superkey OR

✅ 3NF
2.​ Y is a prime attribute (part of a candidate key)


●​ A → B: A is not a superkey, but B is prime (part of key D) →
●​ B → C: B is not a superkey, but C is prime → 3NF

Since all violations have prime attributes on the right side, R is in 3NF but not in BCNF.

Step 3: Decomposing into BCNF

To convert to BCNF, we decompose:

1.​ Create a relation for A → B​


R1(A, B) → A is the key
2.​ Create a relation for B → C​
R2(B, C) → B is the key
3.​ Retain a relation for D → AC​
R3(D, A, C) → D is the key

Final BCNF decomposition:

●​ R1(A, B)
●​ R2(B, C)
●​ R3(D, A, C)

Task 3: Normalization for the Interviews Table

Given Schema:

interviews(interviewer, applicant, day, time, room)


Step 1: Identify Functional Dependencies

From the problem description, we can identify the following functional dependencies:

1.​ (interviewer, day) → room (Each interviewer uses the same room for all interviews
on a given day)
2.​ (interviewer, applicant, day) → time (An applicant is interviewed by an interviewer
on a specific day at a specific time)
3.​ (applicant, day, time) → interviewer (An applicant has one interviewer at a specific
time on a specific day)

Step 2: Find Candidate Keys

We need an attribute set that determines all attributes.

●​ (interviewer, applicant, day, time) determines everything


●​ No smaller subset determines all attributes.

So, (interviewer, applicant, day, time) is the only candidate key.

Step 3: Checking for 3NF and BCNF

Checking BCNF

A relation is in BCNF if for every FD, the left-hand side is a superkey.



●​ (interviewer, day) → room: Not a superkey (violates BCNF)
●​ (interviewer, applicant, day) → time: Not a superkey (violates BCNF)

Since some dependencies violate BCNF, the relation is not in BCNF, but we must check
3NF.

Checking 3NF

A relation is in 3NF if every Y in X → Y is either:

●​ A prime attribute (part of a key)


●​ Or X is a superkey

Since some attributes on the right-hand side are prime, it is in 3NF.

Step 4: Decomposing into BCNF

To convert the relation into BCNF, we decompose it into smaller relations:

1.​ Create a relation for interview times:


○​ R1(interviewer, applicant, day, time)
○​ (interviewer, applicant, day) → time
2.​ Create a relation for room assignments:
○​ R2(interviewer, day, room)
○​ (interviewer, day) → room

Final BCNF decomposition:

●​ R1(interviewer, applicant, day, time)


●​ R2(interviewer, day, room)

Step 5: Drawing the ER Diagram

To model the interview system in an E/R diagram, we need:

●​ Entities:
○​ Interviewer
○​ Applicant
○​ Room
●​ Relationships:
○​ Interviews (between Interviewer and Applicant)
○​ Takes Place In (between Interview and Room)
●​ Attributes:
○​ Interview (day, time)
○​ Room (ID, Location)

Use MySQL Workbench or TOAD to draw the ER diagram.

Final Summary

●​ Task 1: Candidate key is AB.


●​ Task 2: Candidate key is D, relation is not in BCNF, decomposed into three tables.
●​ Task 3: Identified functional dependencies, found candidate key, showed 3NF but not
BCNF, decomposed into BCNF.

Laboratory Exercise #8

Task 1: Person, Children, and Cars Database

Given Relation Schema:

personData(pID, pName, pAddress, cID, cName, cAddress, alic, aMake)

Where:

●​ pID, pName, pAddress: Information about a person.


●​ cID, cName, cAddress: Information about a child.
●​ alic, aMake: License number and make of a car.
●​ A person has exactly one address.
●​ A car may be owned by more than one person.

Step 1: Identifying Functional Dependencies (FDs)

From the problem statement, we derive the following FDs:

1.​ pID → pName, pAddress (A person has exactly one name and address)
2.​ cID → cName, cAddress (A child has exactly one name and address)
3.​ alic → aMake (A car license uniquely determines its make)
4.​ pID, alic → aMake (A person owns a specific car)
5.​ pID, cID → cName, cAddress (A parent-child relationship is unique)

Step 2: Finding Candidate Keys

A candidate key is a minimal set of attributes that determines all attributes in the relation.

●​ pID alone cannot be a key because a person can have multiple cars and children.
●​ cID alone cannot be a key because a child does not determine everything.
●​ alic alone is not a key because cars may be owned by multiple people.
●​ (pID, cID, alic) determines everything.

Thus, the candidate key is (pID, cID, alic).

Step 3: Checking BCNF

A relation is in BCNF if every FD has a superkey on the left-hand side.

●​ pID → pName, pAddress: pID is not a superkey → Violates BCNF.


●​ cID → cName, cAddress: cID is not a superkey → Violates BCNF.
●​ alic → aMake: alic is not a superkey → Violates BCNF.

Since we have violations, the relation is not in BCNF.

Step 4: Decomposing into BCNF

Step 4.1: Remove pID → pName, pAddress

Create a separate table for persons:

Person(pID, pName, pAddress)

Step 4.2: Remove cID → cName, cAddress


Create a separate table for children:

Child(cID, cName, cAddress)

Step 4.3: Remove alic → aMake

Create a separate table for cars:

Car(alic, aMake)

Step 4.4: Create relationships

●​ PersonChild(pID, cID)
●​ Ownership(pID, alic)

Final BCNF Relations:

1.​ Person(pID, pName, pAddress)


2.​ Child(cID, cName, cAddress)
3.​ Car(alic, aMake)
4.​ PersonChild(pID, cID) (Parent-child relationship)
5.​ Ownership(pID, alic) (Person-car ownership relationship)

Step 5: Checking for 4NF Violations

4NF is violated if there is a multi-valued dependency (MVD) where one attribute set is independent
of another but stored in the same relation.

●​ Ownership(pID, alic) violates 4NF because a car can have multiple owners and a person
can own multiple cars.

Step 6: Decomposing into 4NF

To fix this, we decompose Ownership(pID, alic) into:

1.​ PersonOwns(pID, alic) (Captures which person owns which car)


2.​ CarInfo(alic, aMake) (Captures car details)

Step 7: E/R Diagram

●​ Entities: Person, Child, Car


●​ Relationships:
○​ Parent-Child Relationship (One-to-Many)
○​ Person-Car Ownership (Many-to-Many)

Task 2: Company and Projects Database


Given Information:

●​ Each project has a name and runs at a specific location.


●​ Multiple projects may have the same name at the same location.
●​ Each project has a telephone number (shared by projects at the same location).
●​ Each project has a boss (an employee).
●​ Employees have a person number, address, and telephone numbers (each may have
multiple phones).
●​ Employees work on multiple projects, and each project assignment has a start and end
date.

Step 1: E/R Model

Entities:

●​ Project (ProjectID, Name, Location, Telephone, BossID)


●​ Employee (EmpID, Name, Address, PhoneNumbers)
●​ ProjectEmployment (EmpID, ProjectID, StartDate, EndDate)

Relationships:

●​ Project-Employee (One-to-Many: A project has one boss, but an employee can be a


boss of multiple projects)
●​ Employee-Project (Many-to-Many: Employees work on multiple projects)
●​ Employee-PhoneNumbers (One-to-Many: Employees have multiple phone numbers)

Step 2: Converting E/R Model to Relations

1.​ Project(ProjectID, Name, Location, Telephone, BossID)


○​ Primary Key: (ProjectID)
○​ Foreign Key: BossID → Employee(EmpID)
2.​ Employee(EmpID, Name, Address)
○​ Primary Key: (EmpID)
3.​ EmployeePhones(EmpID, PhoneNumber)
○​ Primary Key: (EmpID, PhoneNumber)
○​ Foreign Key: EmpID → Employee(EmpID)
4.​ ProjectEmployment(EmpID, ProjectID, StartDate, EndDate)
○​ Primary Key: (EmpID, ProjectID, StartDate)
○​ Foreign Keys:
■​ EmpID → Employee(EmpID)
■​ ProjectID → Project(ProjectID)

Step 3: Proving BCNF

A relation is in BCNF if for every FD, the left-hand side is a superkey.

Checking BCNF for Each Relation:


1.​ Project(ProjectID, Name, Location, Telephone, BossID)


○​ FDs: ProjectID → Name, Location, Telephone, BossID
○​ ProjectID is a superkey → BCNF
2.​ Employee(EmpID, Name, Address)


○​ FDs: EmpID → Name, Address
○​ EmpID is a superkey → BCNF


3.​ EmployeePhones(EmpID, PhoneNumber)
○​ FDs: (EmpID, PhoneNumber) is the key → BCNF


4.​ ProjectEmployment(EmpID, ProjectID, StartDate, EndDate)
○​ FDs: (EmpID, ProjectID, StartDate) is the key → BCNF

Thus, all relations are in BCNF.

You might also like