Skip to content
Part IA Michaelmas Term

Three Data Models

Overview

The course covers three data models. The relational model has been the industry mainstay for over 48 years; the other two are representatives of the NoSQL movement.

ModelStructureQuery languageOptimised for
RelationalTablesSQLHigh throughput of concurrent updates
Document-orientedNested documents (JSON)Python API, path queriesRead-heavy workloads, semi-structured data
Graph-orientedNodes and edgesCypherPath-oriented queries, network traversal

All three primarily hold discrete data. The Lent term MLRD course deals with soft/continuous decision making.

Relational model

Data is stored in 2-D tables:

  • Each row is a record (tuple).
  • Each column is a field (attribute).
  • The schema indicates field names, data formats, and which column(s) comprise the key.
  • Row and column ordering is unimportant.
  • SQL is the main query language.

Example table:

NameCRSIDCollegeYear
Aliceabc12King’s2
Bobdef34Trinity1
Charlieghi56St John’s3

The primary key (underlined in schema diagrams) is CRSID.

The relational model has been the industry mainstay since the 1970s due to its strong theoretical foundation (relational algebra, normalisation) and robust ACID transaction support.

Document-oriented model

Also called aggregate-oriented database. Instead of splitting data across normalised tables, related data is stored together as a single document.

  • Optimised for read-oriented databases with few updates.
  • Uses semi-structured data (typically JSON).
  • No rigid schema: different documents can have different fields.
  • Queries are expressed in the host programming language or via path expressions.

Example document (JSON):

{
  "name": "Alice",
  "crsid": "abc12",
  "college": "King's",
  "papers": [
    {"code": "CS1", "title": "Foundations of CS"},
    {"code": "CS2", "title": "Software Engineering"}
  ]
}

Graph-oriented model

Data is represented as nodes (entities) and edges (relationships). Both nodes and edges can carry properties.

  • Query languages tend to have path-oriented capabilities.
  • Extensive support for standard graph techniques: shortest path, breadth-first search, PageRank.
  • Well-suited to highly connected data (social networks, recommendation engines, transport networks).

Example (Cypher):

CREATE (alice:Student {name: 'Alice', crsid: 'abc12'})
CREATE (bob:Student {name: 'Bob', crsid: 'def34'})
CREATE (alice)-[:FRIEND_OF]->(bob)

Three database systems used in the course

SystemTypeQuery languageNotes
SQLiteRelationalSQLOpen-source, embedded, single-file database
TinyDBDocument-orientedPython APIOpen-source, in-process, no server required
Neo4jGraph-orientedCypherJava-based, client-server architecture

Examination

For examination purposes, students must learn everything in the slide deck and know all glossary terms. A relational database consists of 2-D tables; the schema indicates field names, data formats, and which column(s) comprise the key (conventionally underlined). Row and column ordering is unimportant.

Summary

  • The three data models are relational (tables + SQL), document-oriented (JSON + path queries), and graph-oriented (nodes/edges + Cypher).
  • The relational model dominates industry; the NoSQL models address specific use cases (semi-structured data, highly connected data).
  • The course uses SQLite, TinyDB, and Neo4j as concrete exemplars.