CSC 313 Manual Solution by Code AJ
CSC 313 Manual Solution by Code AJ
6. Find all the products whose description is ‘1.44 Drive’ and ‘1.22 Drive’
7. Find all the products whose sell price is greater than 5000
8. Find the list of all clients who stay in the city ‘Kaduna’ or city ‘Jos’ or city ‘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
2. Delete the record with client no '0001' from the client_master relation
DELETE FROM client_master
WHERE client_no = '0001';
4. Find out the clients who stay in a city whose second letter is 'a'
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
Relational Algebra:
πprojlD, name, city (projects)
SQL Equivalent:
SELECT * FROM projects;
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
Laboratory Exercise #5
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
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.
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.
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.
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
Laboratory Exercise #6
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.
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.
⚡
3. Paste the generated SQL code in the query window.
4. Click Execute ( ) to create the tables in your database.
After creating the tables, you can add sample data using the following SQL:
Laboratory Exercise #7
1. A→C
2. B→D
3. AC → D
4. CD → E
5. E→A
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)
Candidate Key: AB
1. D → AC
2. A → B
3. B → C
D → AC
A → B
B→C
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:
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.
● R1(A, B)
● R2(B, C)
● R3(D, A, C)
Given Schema:
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)
Checking BCNF
❌
❌
● (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
● Entities:
○ Interviewer
○ Applicant
○ Room
● Relationships:
○ Interviews (between Interviewer and Applicant)
○ Takes Place In (between Interview and Room)
● Attributes:
○ Interview (day, time)
○ Room (ID, Location)
Final Summary
Laboratory Exercise #8
Where:
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)
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.
Car(alic, aMake)
● PersonChild(pID, cID)
● Ownership(pID, alic)
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.
Entities:
Relationships:
✅
○ 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