Learning Objectives

By the end of this chapter, you will be able to:

  • Define a database model.
  • Describe the hierarchical and network models.
  • Explain the structure of the relational model, including primary and foreign keys.
  • Understand the importance of the relational model in modern databases.
  • Describe newer models such as object-oriented and NoSQL databases.

What are Database Models?

A database model is a set of rules and standards that defines the logical structure of a database. It determines how data is stored, organized, and manipulated. Several models have been developed over the years, but the relational model is by far the most common.

1. Hierarchical Model

This is one of the oldest models. It organizes data in a tree-like structure, with a single root at the top and branches below. Each child record has only one parent.

  • Analogy: A family tree.
  • Example: A company → departments → employees; IBM’s IMS system (1960s) used this model.
  • Advantage: Fast and simple for data that is naturally one-to-many.
  • Disadvantage: It is very rigid. You can only access data by starting at the root and moving down the tree.
flowchart TB
  C[Company] --> D1[Sales Department]
  C --> D2[Accounts Department]
  D1 --> E1[Employee: Ram]
  D1 --> E2[Employee: Sita]
  D2 --> E3[Employee: Hari]

2. Network Model

The network model is an extension of the hierarchical model. It allows each child record to have multiple parent records, creating a more flexible, graph-like structure.

  • Example: A student enrolled in several courses, and each course having many students (many-to-many).
  • Advantage: More flexible than the hierarchical model.
  • Disadvantage: Still complex to navigate and manage.

3. Relational Model

Developed by E.F. Codd in 1970, the relational model is the basis for almost all modern database systems. It organizes data into simple two-dimensional tables (also called relations), which are composed of rows and columns.

  • Tables: Store data about a specific entity (e.g., Customers, Products).
  • Rows (Records): Represent a single instance of that entity (e.g., one customer).
  • Columns (Fields): Represent an attribute of that entity (e.g., CustomerName).

Tables are linked together using keys. The data can be easily manipulated and queried using a specialized language, most commonly SQL (Structured Query Language).

  • Advantage: Very flexible, easy to understand, and allows for powerful querying of data.

Keys: how tables are linked

  • Primary key: a field that uniquely identifies each row (e.g., StudentID).
  • Foreign key: a field in one table that refers to the primary key of another table, creating a relationship.

Students

StudentID (PK) Name Program
S01 Sita Sharma BBM
S02 Ram Thapa BBA

Enrollments

StudentID (FK) CourseCode Semester
S01 IT231 2
S01 ACC201 2
S02 IT231 2

A simple SQL query can combine them, for example to list all students enrolled in IT231:

SELECT Students.Name
FROM Students
JOIN Enrollments ON Students.StudentID = Enrollments.StudentID
WHERE Enrollments.CourseCode = 'IT231';

Types of relationships: one-to-one (a person and a passport), one-to-many (a customer and many orders), and many-to-many (students and courses, handled through a linking table like Enrollments).

4. Newer models

  • Object-oriented model: Stores data as objects (data plus behaviour), as in object-oriented programming; useful for complex data such as engineering designs and multimedia.
  • NoSQL databases: Flexible models designed for huge volumes and varied data, including document (MongoDB), key-value (Redis), column-family (Cassandra), and graph (Neo4j) databases. Used by social media, e-commerce, and big data applications.

Comparison of Models

Model Structure Relationships Flexibility Example use
Hierarchical Tree One-to-many only Low Early banking and airline systems
Network Graph Many-to-many Medium Older manufacturing systems
Relational Tables Through keys; any type High Banking, college, retail systems
NoSQL Documents, key-value, graphs Flexible Very high Social media, big data, real-time apps

Summary

Database models define the logical structure of a database. While early models like the hierarchical and network models were influential, they were largely replaced by the much more flexible and powerful relational model. The relational model, which organizes data into simple tables linked by primary and foreign keys, is the foundation of nearly all modern databases and is queried using the standard language SQL. Object-oriented and NoSQL models serve special needs such as complex objects and very large, varied data.

Key Takeaways

  • A database model defines the logical structure of a database.
  • The hierarchical model is a rigid tree-like structure.
  • The network model is a more flexible graph-like structure.
  • The relational model, which uses tables, is the most common model used today.
  • Primary and foreign keys link tables in a relational database.
  • NoSQL databases handle very large and varied data.

Discussion Questions

  1. Why is the relational model so much more popular than the hierarchical or network models?
  2. What is the role of SQL in a relational database?
  3. Draw a simple relational database with two tables (e.g., Students and Courses) and show how they might be related.

Exam-Style Questions

Short answer

  1. What is a database model? Name four models.
  2. Differentiate between a primary key and a foreign key.
  3. What is NoSQL?

Long answer

  1. Explain the hierarchical, network, and relational models with diagrams.
  2. Describe the relational model with an example of two related tables. Why is it the most popular model?