Unit 3: The relational data model
Database Management Systems notes · PTU syllabus (BSIT402/BSBC404)
On this page
- Unit summary
- Relational database
- Relational algebra
- Relational calculus
- SQL: command categories
- SQL queries: aggregates, operators and clauses
- Functional dependencies
- Armstrong's axioms and closure
- Multivalued and join dependencies
- Normalisation: anomalies
- Normal forms
- Key terms
- Quick revision
- Important questions
Unit summary
The relational model rests on a sound mathematical base. This unit covers relational databases, relational algebra and relational calculus, SQL, and dependencies — functional, multivalued and join dependencies — leading to normalisation.
After this unit you can
- Write relational algebra and calculus expressions
- Write SQL queries
- Identify functional, multivalued and join dependencies
- Normalise relations up to 5NF
PTU syllabus topics
- Relational database
- relational algebra and calculus
- SQL
- dependencies — functional dependency
- multi-valued dependency
- join dependency
- normalization
- 1
Unnormalised data
Repeating groups
- 2
1NF
Atomic values, no repeating groups
- 3
2NF
No partial dependency on part of a key
- 4
3NF
No transitive dependency
- 5
BCNF
Every determinant is a candidate key
- 6
4NF and 5NF
No multi-valued or join dependencies
Topic 1
Relational database
- A relational database is a collection of relations with a schema, keys and constraints, managed by an RDBMS that supports SQL.
- Super key
- Any attribute set that identifies tuples uniquely
- Candidate key
- Minimal super key
- Primary key
- Candidate key chosen to identify tuples
- Alternate key
- Candidate keys not chosen
- Foreign key
- Attribute referring to another relation's primary key
- Composite key
- Key made of two or more attributes
Topic 2
Relational algebra
| Operation | Symbol | Meaning |
|---|---|---|
| Selection | σ | Chooses rows satisfying a condition: σ age>20 (STUDENT) |
| Projection | π | Chooses columns: π name, course (STUDENT) |
| Union | ∪ | Rows in either relation (union-compatible) |
| Intersection | ∩ | Rows in both relations |
| Set difference | − | Rows in the first but not the second |
| Cartesian product | × | Every row of one with every row of the other |
| Join | ⋈ | Product followed by a selection on matching columns |
| Division | ÷ | Rows related to all rows of another relation |
Example
Names of BCA students: π name (σ course = 'BCA' (STUDENT)).
Example
Students enrolled in every course: π Roll, Code (ENROLS) ÷ π Code (COURSE).
Topic 3
Relational calculus
- Relational calculus is non-procedural: it states what to retrieve, while relational algebra states how.
Variables range over
Tuples of a relation
Values of attributes (domains)
General form
{ t such that P(t) }
{ ⟨x1, x2, ...⟩ such that P(x1, x2, ...) }
Example: students with marks over 75
{ t.Name such that t ∈ STUDENT and t.Marks > 75 }
{ ⟨n⟩ such that ∃ r, m (⟨r, n, m⟩ ∈ STUDENT and m > 75) }
Based language
SQL
QBE (Query By Example)
- Quantifiers: ∃ (there exists) and ∀ (for all). Codd's theorem: relational algebra and safe relational calculus have the same expressive power (relational completeness).
Topic 4
SQL: command categories
DDL
Define structure
CREATE, ALTER, DROP, TRUNCATE, RENAME
DML
Change data
INSERT, UPDATE, DELETE
DQL
Query data
SELECT
DCL
Control access
GRANT, REVOKE
TCL
Manage transactions
COMMIT, ROLLBACK, SAVEPOINT
sqlCREATE TABLE student (
roll INT PRIMARY KEY,
name VARCHAR(40) NOT NULL,
course VARCHAR(10),
marks INT CHECK (marks BETWEEN 0 AND 100)
);
INSERT INTO student VALUES (1, 'Ana', 'BCA', 82);
UPDATE student SET marks = 85 WHERE roll = 1;
SELECT name, marks FROM student WHERE course = 'BCA' ORDER BY marks DESC;Topic 5
SQL queries: aggregates, operators and clauses
- Aggregate functions: COUNT, SUM, AVG, MIN, MAX.
- Operators and predicates: AND, OR, NOT, BETWEEN, IN, LIKE ('A%' starts with A), IS NULL.
- GROUP BY groups rows; HAVING filters groups; ORDER BY sorts.
sqlSELECT course, COUNT(*) AS students, AVG(marks) AS average
FROM student
GROUP BY course
HAVING AVG(marks) > 60
ORDER BY average DESC;Exam tip
WHERE filters rows before grouping; HAVING filters groups after grouping. This difference is asked very often.
Topic 6
Functional dependencies
A functional dependency (FD) X → Y means the value of X uniquely determines the value of Y. Example: RollNo → Name.
- Trivial FD: Y is a subset of X (e.g. {RollNo, Name} → Name).
- Full FD: Y depends on the whole of X, not on any part of it.
- Partial FD: Y depends on part of a composite key.
- Transitive FD: X → Y and Y → Z give X → Z, where Y is not a key.
- Multivalued dependency (MVD): X →→ Y, one X value has a set of independent Y values.
Topic 7
Armstrong's axioms and closure
- Reflexivity
- If Y ⊆ X, then X → Y
- Augmentation
- If X → Y, then XZ → YZ
- Transitivity
- If X → Y and Y → Z, then X → Z
- Union (derived)
- If X → Y and X → Z, then X → YZ
- Decomposition (derived)
- If X → YZ, then X → Y and X → Z
The closure of an attribute set X⁺ is the set of all attributes functionally determined by X. If X⁺ contains every attribute, X is a super key.
Example
R(A, B, C, D) with A → B, B → C. A⁺ = {A, B, C}. Since D is missing, A is not a key; (AD)⁺ = {A, B, C, D}, so AD is a key.
Topic 8
Multivalued and join dependencies
- Multivalued dependency (MVD) X →→ Y: for each X value there is a set of Y values independent of the other attributes.
Example
COURSE_INFO(Course, Teacher, Book): a course has several teachers and several books, chosen independently. Course →→ Teacher and Course →→ Book. Storing them together forces every teacher–book combination; split into (Course, Teacher) and (Course, Book) for 4NF.
- Join dependency (JD): a relation R satisfies the join dependency JD(R1, R2, ..., Rn) if R equals the natural join of its projections on R1 ... Rn — i.e., it can be decomposed losslessly into those parts.
Example
SPJ(Supplier, Part, Project): if "supplier supplies part" and "part used in project" and "supplier supplies project" together imply the triple, SPJ = SP ⋈ PJ ⋈ SJ, and it should be split into three tables for 5NF.
- Every FD is an MVD; every MVD is a JD with two components.
Topic 9
Normalisation: anomalies
In an unnormalised table STUDENT_COURSE(Roll, Name, Course, Faculty):
- Insertion anomaly: a new course cannot be added until a student enrols.
- Update anomaly: changing a faculty name requires updating many rows.
- Deletion anomaly: deleting the last student of a course loses the course's information.
Topic 10
Normal forms
- 1
1NF
Atomic values; no repeating groups
- 2
2NF
1NF + no partial dependency on part of a composite key
- 3
3NF
2NF + no transitive dependency on a non-key attribute
- 4
BCNF
For every FD X → Y, X is a super key
- 5
4NF
BCNF + no non-trivial multivalued dependency
- 6
5NF
4NF + no join dependency (lossless decomposition)
Example
ORDER(OrderID, ProductID, ProductName, Qty) with key (OrderID, ProductID): ProductName depends only on ProductID — a partial dependency. Split into ORDER_ITEM(OrderID, ProductID, Qty) and PRODUCT(ProductID, ProductName) to reach 2NF.
Example
EMP(EmpID, DeptID, DeptName): EmpID → DeptID → DeptName is transitive. Split into EMP(EmpID, DeptID) and DEPT(DeptID, DeptName) for 3NF.
Key terms
- Relational algebra
- Procedural language of operations on relations
- Relational calculus
- Non-procedural language stating what to retrieve
- Functional dependency
- X determines a unique value of Y
- Multivalued dependency
- X determines an independent set of Y values
- Join dependency
- Relation equals the join of its projections
Quick revision
- Keys: super, candidate, primary, alternate, foreign, composite.
- σ, π, ∪, ∩, −, ×, ⋈, ÷.
- TRC and DRC; ∃ and ∀; Codd's theorem.
- DDL, DML, DCL, TCL; aggregates, GROUP BY, HAVING.
- FD, MVD, JD; anomalies; 1NF to 5NF.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.Distinguish relational algebra and relational calculus.
- Q2.What does the projection operation do?
- Q3.Define a candidate key.
- Q4.What is a multivalued dependency?
- Q5.What is a join dependency?
- Q6.State the condition for BCNF.
Long-answer questions
- Q1.Explain the operations of relational algebra with examples.
- Q2.Explain tuple and domain relational calculus.
- Q3.Explain functional, multivalued and join dependencies.
- Q4.Explain normalisation up to 5NF with examples.
Stuck on this unit?
Message SBS on WhatsApp for help with Database Management Systems, or to ask about studying B.Sc IT at Synetic.
