How Data is Organized
Databases can organize data in different ways. The way data is structured is called a data model. Different models are suited for different types of data and different use cases.
Hierarchical Model
Data is organized in a tree structure with parent-child relationships. Each parent can have many children, but each child has only one parent.
Company (Root)
├── Department A
│ ├── Employee 1
│ └── Employee 2
└── Department B
├── Employee 3
└── Employee 4
Used by IBM's IMS (Information Management System) in the 1960s-70s. Simple but rigid — you can't easily represent many-to-many relationships.
Network Model
An extension of the hierarchical model that allows many-to-many relationships. Each record can have multiple parents and multiple children.
Student ←──── Enrollment ────→ Course
│ │
└──→ Advisor └──→ Instructor
More flexible than hierarchical, but complex to navigate. You need to follow pointers to traverse the network of records.
Relational Model
The dominant model since the 1980s. Data is organized in tables (relations) with rows (tuples) and columns (attributes). Relationships between tables are established through keys.
Students Table Courses Table
┌────┬─────────┬────────┐ ┌────┬──────────────┬──────┐
│ ID │ Name │ DeptID │ │ ID │ Title │ Dept │
├────┼─────────┼────────┤ ├────┼──────────────┼──────┤
│ 1 │ Alice │ 10 │ │ 101│ Databases │ 10 │
│ 2 │ Bob │ 20 │ │ 102│ Networking │ 20 │
│ 3 │ Charlie │ 10 │ │ 103│ OS │ 10 │
└────┴─────────┴────────┘ └────┴──────────────┴──────┘
The relational model is based on relational algebra and set theory. It's intuitive, mathematically sound, and supported by SQL.
Object-Relational Model
A hybrid that combines relational tables with object-oriented features. You can define custom types, inheritance, and methods within the database. PostgreSQL supports this model.
NoSQL Models
Document: Key-Value: Graph:
{ ┌─────┬───────┐ (A)──→(B)
"name": "Alice", │ key │ value │ │ │
"age": 25, ├─────┼───────┤ ↓ ↓
"courses": [101,103] │ "a" │ 42 │ (C)──→(D)
} │ "b" │ "hello"│
└─────┴───────┘ Column:
MongoDB, CouchDB Redis, DynamoDB Cassandra
NoSQL databases trade the strict structure of relational models for flexibility, scalability, or performance in specific use cases.