Hierarchical and Network Data Models
The hierarchical model arranges records in a tree with one parent each; the network model allows many parents through a graph of sets. Both used physical pointers, and that is exactly why the relational model replaced them.
-
DBMS Fundamentals
- Data, Information and Databases
- What a DBMS Is and Why It Exists
- File System versus DBMS
- Advantages and Limitations of a DBMS
- Database Users and the Role of the DBA
- Three Level Architecture and Data Abstraction
- Logical and Physical Data Independence
- Schema, Instance and Metadata
- Database Applications and the Database System Environment
- Database Architecture
- Data Models
-
ER Model
- Entities, Entity Sets and Entity Types
- Types of Attributes in the ER Model
- Keys in the ER Model
- Relationships, Relationship Sets and Degree
- Cardinality and Participation Constraints
- Strong and Weak Entities
- Drawing and Reading ER Diagrams
- Extended ER: Generalisation, Specialisation and Aggregation
- Converting an ER Diagram into Relational Tables
- ER Design Projects
- Relational Model
- Relational Algebra
- Functional Dependencies
-
Normalisation
- Why Normalisation Exists: Anomalies and Redundancy
- First Normal Form
- Second Normal Form and Partial Dependency
- Third Normal Form and Transitive Dependency
- BCNF and BCNF Decomposition
- 4NF, 5NF, Multivalued and Join Dependencies
- Lossless Decomposition and Dependency Preservation
- Complete Worked Normalisation: Unnormalised to BCNF
- Denormalisation and When to Use It
Concept
These two models came before the relational model. They are still examined because their weaknesses explain, point by point, why the relational model was designed the way it was.
The hierarchical model
Data is organised as a tree. Every record type except the root has exactly one parent, and a parent may have many children. The relationship is strictly one to many, and it is represented by a physical pointer from parent to child.
COLLEGE
|
+----------+-----------+
| |
DEPARTMENT DEPARTMENT
(Computing) (Commerce)
| |
+----+----+ |
| | |
STUDENT STUDENT STUDENT
Navigation is by path: college -> department -> student.
To reach a student you must walk from the root.Problems with the hierarchical model
- Many to many is not representable. A student taking many courses, and a course taken by many students, does not fit a tree. The workaround is duplicating records, which reintroduces redundancy.
- A child cannot exist without a parent. Deleting a department deletes its students.
- Access is navigational. The programmer must know and follow the path. There is no ad hoc query.
- No data independence. Changing the tree shape rewrites the programs.
The network model
Data is organised as a graph. A record may have several parents. The relationship is expressed as a named set, which has one owner record type and one member record type, again implemented with pointers.
STUDENT COURSE
| / |
| set: ENROLMENT / |
| +----> ENROLS <---+ |
| record |
| |
owner of owner of
set S_E set C_E
A student owns many enrolment records.
A course also owns many enrolment records.
So many to many IS representable - by inserting a
record type between the two, exactly the idea that
becomes the junction table in the relational model.Improvements over hierarchical
- Many to many relationships are supported.
- A record can be reached by more than one path.
- Data retrieval is more flexible.
Problems that remain
- Still navigational. The programmer walks pointers, one record at a time. There is no declarative query.
- Structural complexity. A large network of sets is hard to draw, harder to change.
- Still no data independence. Programs are written against the pointer structure, so changing it breaks them.
- Design changes are expensive. Adding a relationship means adding sets and rewriting access code.
Comparison
| Point | Hierarchical | Network | Relational |
|---|---|---|---|
| Structure | Tree | Graph of sets | Tables |
| Parents per record | Exactly one | Many | Not applicable |
| Many to many | Not supported directly | Supported through a linking record | Supported through a junction table |
| Relationships by | Physical pointers | Physical pointers | Matching values in keys |
| Access | Navigational, from the root | Navigational, along sets | Declarative — state the result wanted |
| Data independence | Very low | Low | High |
| Ad hoc queries | No | Barely | Yes |
| Ease of change | Very hard | Hard | Comparatively easy |
The one sentence that carries the whole comparison: the older models connect records with pointers, the relational model connects them with values. A pointer is a physical fact, so programs depend on physical layout. A value is a logical fact, so they do not. Every advantage in the right hand column follows from that.
Example
"Which students take Database Systems?"
HIERARCHICAL
start at the root, walk every department, walk every
student, inspect their course children, collect matches.
The programmer writes the walk. Adding a level of the
tree means rewriting it.
NETWORK
find the COURSE record for Database Systems, then follow
its enrolment set to each member, then follow each member
back to its owning STUDENT record.
Shorter, still a walk written by hand.
RELATIONAL
state the join between students, enrolments and courses
and let the optimiser decide how to walk it.
The access path is the DBMS decision, not yours.Common mistakes
- Saying the network model cannot do many to many. It can — that is its main improvement over hierarchical.
- Saying the hierarchical model has no relationships. It has one to many relationships, expressed as parent to child.
- Forgetting the real weakness. It is not the shape; it is that both are navigational and pointer based, which destroys data independence.
- Assuming these models are extinct. Hierarchical thinking survives in file systems, XML and JSON documents, and directory services.
Exam and interview questions
- Explain the hierarchical model with a diagram and state two limitations.
- How does the network model represent a many to many relationship?
- Compare hierarchical, network and relational models on at least six points.
- Why did pointer based models fail to provide data independence?
- Give one modern structure that still uses hierarchical thinking.
Practice
- Draw a hospital as a hierarchical model and identify the fact it cannot represent.
- Redraw the same case as a network model and name the linking record type.
- Explain in three sentences why replacing pointers with key values improved data independence.
Conclusion
Hierarchical gives one parent and a tree; network gives many parents and a graph. Both link records with pointers, so both force programs to know the physical structure — and that single flaw is what the relational model was designed to remove.