Part 2 — Data Models, Languages & Relational Algebra

CLO2 · high value. The DDL/DCL/DML/TCL table is pure recall; the relational-algebra parts reward drawing the resultant table carefully.

Q3smallDefine ‘database language’ and fill the DDL / DCL / DML / TCL table (≥3 commands each). (1 + 2)

Relational algebra — the operator toolkit

σ π ∪ − × ρ6 basics: Select (rows) · Project (columns) · Union · Difference · Cartesian product · Rename. Joins are × + σ.

Q4 — Employee & Department

The two given relations:

EIDEmpNameDeptID
1Rahim10
2Karima20
3Sumon10
4Nila30
4 tuples · 3 attributes
DeptIDDeptNameLocation
10HRDhaka
20FinanceChattogram
40ITSylhet
3 tuples · 3 attributes
Spot the mismatch before you start. Employee depts = {10, 20, 30}; Department depts = {10, 20, 40}. So Nila (30) has no department and IT (40) has no employee — exactly what parts (b) and (c) test.
Q4(a)Write the relational algebra for the Cartesian product and draw the complete table. (3)
Q4(b)Write the join that returns all information for employees who belong to a department. Give the resultant table. (2)
Q4(c)What is the output of Employee ⟕ Department, and what information does it give? (3)
Q4(d)Write the join to find all employees who live in Dhaka. Give the resultant table. (3)

Join types — one picture to keep them straight

Inner (⋈)only matchesLeft outer (⟕)all left + NULLsRight outer (⟖)all right + NULLsFull outer (⟗)everything

Filled region = rows kept. Left circle = Employee, right circle = Department.

Operator summary

SymbolNameDoes
σSelectionRows matching a predicate
πProjectionChosen columns; removes duplicates
×Cartesian productAll row pairs of two relations
∪ · − · ∩Set opsUnion · difference · intersection
Natural join× then match same-named attributes
⟕ ⟖ ⟗Outer joinsKeep unmatched left / right / both as NULL
ρRenameRename a relation / its attributes

Want to try these live on other data? Open the RA Playground →