Unit 3 of 4 · B.Sc IT Sem 4

Unit 3: The relational data model

Database Management Systems notes · PTU syllabus (BSIT402/BSBC404)

4 min read10 topics10 exam questions
On this page
  1. Unit summary
  2. Relational database
  3. Relational algebra
  4. Relational calculus
  5. SQL: command categories
  6. SQL queries: aggregates, operators and clauses
  7. Functional dependencies
  8. Armstrong's axioms and closure
  9. Multivalued and join dependencies
  10. Normalisation: anomalies
  11. Normal forms
  12. Key terms
  13. Quick revision
  14. 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
ProcessNormalisation steps
  1. 1

    Unnormalised data

    Repeating groups

  2. 2

    1NF

    Atomic values, no repeating groups

  3. 3

    2NF

    No partial dependency on part of a key

  4. 4

    3NF

    No transitive dependency

  5. 5

    BCNF

    Every determinant is a candidate key

  6. 6

    4NF and 5NF

    No multi-valued or join dependencies

1

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.
Key termsKeys
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
2

Topic 2

Relational algebra

OperationSymbolMeaning
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).

3

Topic 3

Relational calculus

  • Relational calculus is non-procedural: it states what to retrieve, while relational algebra states how.
ComparisonTuple and domain relational calculus
Tuple relational calculus (TRC)
Domain relational calculus (DRC)

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).
4

Topic 4

SQL: command categories

ComparisonSQL sub-languages
Purpose
Commands

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;
5

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.

6

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.
7

Topic 7

Armstrong's axioms and closure

Key termsArmstrong's axioms
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.

8

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.
9

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.
10

Topic 10

Normal forms

ProcessSteps of normalisation
  1. 1

    1NF

    Atomic values; no repeating groups

  2. 2

    2NF

    1NF + no partial dependency on part of a composite key

  3. 3

    3NF

    2NF + no transitive dependency on a non-key attribute

  4. 4

    BCNF

    For every FD X → Y, X is a super key

  5. 5

    4NF

    BCNF + no non-trivial multivalued dependency

  6. 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

  1. Q1.Distinguish relational algebra and relational calculus.
  2. Q2.What does the projection operation do?
  3. Q3.Define a candidate key.
  4. Q4.What is a multivalued dependency?
  5. Q5.What is a join dependency?
  6. Q6.State the condition for BCNF.

Long-answer questions

  1. Q1.Explain the operations of relational algebra with examples.
  2. Q2.Explain tuple and domain relational calculus.
  3. Q3.Explain functional, multivalued and join dependencies.
  4. 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.

WhatsApp us