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.
| Model | Structure | Query language | Optimised for |
|---|---|---|---|
| Relational | Tables | SQL | High throughput of concurrent updates |
| Document-oriented | Nested documents (JSON) | Python API, path queries | Read-heavy workloads, semi-structured data |
| Graph-oriented | Nodes and edges | Cypher | Path-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:
| Name | CRSID | College | Year |
|---|---|---|---|
| Alice | abc12 | King’s | 2 |
| Bob | def34 | Trinity | 1 |
| Charlie | ghi56 | St John’s | 3 |
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
| System | Type | Query language | Notes |
|---|---|---|---|
| SQLite | Relational | SQL | Open-source, embedded, single-file database |
| TinyDB | Document-oriented | Python API | Open-source, in-process, no server required |
| Neo4j | Graph-oriented | Cypher | Java-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.