Docsity

Databases: Relational Model, SQL, Normalisation and Transactions, Study notes of Computer Science

Toggle sidebar
bg1
Databases: Relational Model, SQL, Normalisation and Transact Page 1 of 3
Databases: Relational Model, SQL, Normalisation and
Transactions
The definitions, normal forms and transaction properties that exam questions test
Computer Science | Undergraduate (Level 5) | December 2026
WHAT IS INSIDE
1. The relational model
2. SQL and relational algebra
3. Functional dependencies and normalisation
4. Transactions, concurrency and indexes
Exam question patterns
Glossary of exam-ready definitions
1. The relational model
A relation is a set of tuples over a schema of named, typed attributes; because it is a set, duplicate tuples are
impossible and tuple order carries no meaning. A superkey uniquely identifies a tuple, a candidate key is a
minimal superkey, and the primary key is the candidate key chosen for identification. A foreign key
references a candidate key in another relation and enforces referential integrity: its value must exist there or be
null where permitted.
Integrity constraints are declared, not assumed: entity integrity forbids null primary keys, referential integrity
forbids dangling references, and domain constraints restrict values to their type. The important exam distinction
is between the schema (the stable structure) and the instance (the current data), because constraints are stated
on the schema and evaluated on the instance. Relational design also explains why a table without a declared key
is not a relation in the formal sense, however it looks in a spreadsheet.
•Degree and cardinality - degree is the number of attributes, cardinality the number of tuples.
•Null - unknown, not applicable or withheld; comparisons with null yield unknown, never true.
•Referential action - restrict, cascade or set null defines what happens on deletion of a referenced row.
•View - a stored query; a materialised view trades storage and staleness for read speed.
2. SQL and relational algebra
Relational algebra is the formal basis: selection filters rows, projection chooses columns, cartesian product
pairs rows, join pairs rows matching on a condition, and set operations combine compatible relations. SQL
adds duplicate retention, ordering and aggregation, so a SQL query is not identical to an algebraic expression
until duplicates are removed. Exam questions typically ask you to translate between the two; translate
projection last, because the algebra collapses duplicates on projection while SQL does not without DISTINCT.
The clauses are evaluated in a fixed logical order: FROM, WHERE, GROUP BY, HAVING, SELECT,
ORDER BY. That order explains why an alias defined in SELECT cannot be used in WHERE, and why
filtering an aggregate needs HAVING rather than WHERE. Outer joins preserve unmatched rows with nulls,
and the classic error is turning an outer join back into an inner one by testing a column of the optional side in
WHERE instead of in the join condition.
•Aggregate functions - COUNT, SUM, AVG, MIN, MAX; COUNT(*) counts rows while COUNT(column)
ignores nulls.
•Subquery forms - scalar, IN, EXISTS and correlated; EXISTS stops at the first match, which matters for
performance.
pf3

Partial preview of the text

Download Databases: Relational Model, SQL, Normalisation and Transactions and more Study notes Computer Science in PDF only on Docsity!

Databases: Relational Model, SQL, Normalisation and

Transactions

The definitions, normal forms and transaction properties that exam questions test Computer Science | Undergraduate (Level 5) | December 2026

WHAT IS INSIDE

  1. The relational model
  2. SQL and relational algebra
  3. Functional dependencies and normalisation
  4. Transactions, concurrency and indexes Exam question patterns Glossary of exam-ready definitions

1. The relational model

A relation is a set of tuples over a schema of named, typed attributes; because it is a set, duplicate tuples are impossible and tuple order carries no meaning. A superkey uniquely identifies a tuple, a candidate key is a minimal superkey, and the primary key is the candidate key chosen for identification. A foreign key references a candidate key in another relation and enforces referential integrity: its value must exist there or be null where permitted.

Integrity constraints are declared, not assumed: entity integrity forbids null primary keys, referential integrity forbids dangling references, and domain constraints restrict values to their type. The important exam distinction is between the schema (the stable structure) and the instance (the current data), because constraints are stated on the schema and evaluated on the instance. Relational design also explains why a table without a declared key is not a relation in the formal sense, however it looks in a spreadsheet.

  • Degree and cardinality - degree is the number of attributes, cardinality the number of tuples.
  • Null - unknown, not applicable or withheld; comparisons with null yield unknown, never true.
  • Referential action - restrict, cascade or set null defines what happens on deletion of a referenced row.
  • View - a stored query; a materialised view trades storage and staleness for read speed.

2. SQL and relational algebra

Relational algebra is the formal basis: selection filters rows, projection chooses columns, cartesian product pairs rows, join pairs rows matching on a condition, and set operations combine compatible relations. SQL adds duplicate retention, ordering and aggregation, so a SQL query is not identical to an algebraic expression until duplicates are removed. Exam questions typically ask you to translate between the two; translate projection last, because the algebra collapses duplicates on projection while SQL does not without DISTINCT.

The clauses are evaluated in a fixed logical order: FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY. That order explains why an alias defined in SELECT cannot be used in WHERE, and why filtering an aggregate needs HAVING rather than WHERE. Outer joins preserve unmatched rows with nulls, and the classic error is turning an outer join back into an inner one by testing a column of the optional side in WHERE instead of in the join condition.

  • Aggregate functions - COUNT, SUM, AVG, MIN, MAX; COUNT(*) counts rows while COUNT(column) ignores nulls.
  • Subquery forms - scalar, IN, EXISTS and correlated; EXISTS stops at the first match, which matters for performance.

Databases: Relational Model, SQL, Normalisation and Transactions

  • Three-valued logic - NOT IN with a null in the list returns no rows; use NOT EXISTS instead.
  • Window functions - ROW_NUMBER, RANK and running sums without collapsing groups.

3. Functional dependencies and normalisation

A functional dependency X determines Y where every pair of tuples agreeing on X agrees on Y. Armstrong's axioms - reflexivity, augmentation and transitivity - derive the closure, and a minimal cover removes redundant attributes and redundant dependencies. Normalisation removes redundancy that causes update anomalies: insertion, deletion and modification anomalies all follow from storing one fact in many places, and each is examinable by example.

The forms build on each other. 1NF requires atomic values and no repeating groups. 2NF removes partial dependencies on part of a composite key. 3NF removes transitive dependencies, so every non-key attribute depends on the key and nothing else. BCNF requires every determinant to be a candidate key, which is stricter than 3NF when a relation has overlapping candidate keys. Denormalisation is a deliberate performance decision, and the correct exam answer names the redundancy reintroduced and the anomaly accepted in exchange.

  • Lossless join - a decomposition must reconstruct the original relation exactly; test with the chase or by intersecting attributes.
  • Dependency preservation - BCNF may lose a dependency, which is why 3NF is sometimes preferred.
  • 4NF and 5NF - deal with multivalued and join dependencies, rare in practice but asked conceptually.
  • Surrogate versus natural key - surrogate keys are stable; natural keys carry meaning but change.

4. Transactions, concurrency and indexes

A transaction is a unit of work satisfying ACID : atomicity (all or nothing), consistency (constraints hold before and after), isolation (concurrent execution behaves as if serial), and durability (committed work survives failure). The isolation levels are defined by the anomalies they permit: read uncommitted allows dirty reads, read committed prevents them, repeatable read prevents non-repeatable reads, and serialisable prevents phantoms as well. Every step down costs concurrency, which is the trade-off a question about banking throughput is really asking about.

Concurrency control uses two-phase locking (growing then shrinking phase) or timestamp ordering or multiversion schemes; a deadlock is a cycle in the wait-for graph, prevented by ordering resource acquisition or resolved by aborting a victim. Indexes - B+ trees for range queries, hash indexes for equality, and composite indexes where the leftmost prefix rule decides usability - trade write cost and storage for read speed. A query plan that ignores an index is usually caused by a function applied to the indexed column or by a type mismatch.

  • Write-ahead logging - log before data; redo restores committed work, undo removes uncommitted work.
  • Phantom read - a repeat query returns new rows; prevented by range locks or serialisable isolation.
  • Optimistic concurrency - version checks at commit; efficient under low contention, retries under high.
  • Covering index - contains every column the query needs, so the table is never read. Normal form Condition Anomaly removed 1NF Atomic attribute values, no repeating groups Multi-valued cells 2NF 1NF plus no partial dependency on part of a key Duplication across composite keys 3NF 2NF plus no transitive dependency Non-key attribute depending on another BCNF Every determinant is a candidate key Overlapping candidate key anomalies 4NF No non-trivial multivalued dependency Independent multi-valued facts combined

State the dependency you are removing at each step, not just the form number: marks are given for the dependency, and the form follows from it.