If you’re like me and you’re learning how to design a database, then you need to know what a database model is. I just finished my introductory database design course at my University, so I know a bit about it. Below I describe exactly what a database model is and give a few examples so you know which database model to choose for your project.
What Is A Database Model?
A database model refers to the structure of a database and determines how the data within the database can be organized and manipulated. There are several types of database models including the relational model, the hierarchical model, the network model, the object-oriented model, and more. The most common database model today is the relational model.
Relational Database (The Most Common Model)
A relational database model is the most commonly used model when constructing or redesigning a database. The relational model consists of multiple tables that bear some relationship with each other. Each table contains attributes that are the key that forms these relationships.
For example, consider the tables below:
There is a table for Students that contains attributes for their student ID, their first and last name, and their email.
There is another table for Classes that contains attributes for the class ID, the class name, and the professor for the class.
Last, there is a table for the Registered Classes which has a register ID, term, and two attributes taken from the previous two tables: student ID, and class ID. This represents how these tables are related to each other and thus, how relational models are structured.
Advantages of Relational Model
- Easy to use
Disadvantages of Relational Model
- Slow extraction
- High memory consumption
Hierarchical Database Model (Least Common)
The hierarchical database model is a very structured top-down way of organizing data. That’s to say that the data in this model is organized in a tree-like structure with the top of the tree being the top of the hierarchy.
For example, consider the hierarchical model of a University:
The hierarchical database model was popular in the early days of the digital database in the 1950s and 1960s as people transitioned from the paper filing of data. That’s why hierarchical databases are organized in the same fashion as a filing cabinet. However, it’s not a commonly used database model anymore.
Advantages of Hierarchical Model
- Easy addition and deletion of data
- Relates to natural hierarchies
- Supports one-to-many relationships
Disadvantages of Hierarchical Model
- Not scalable
- Not flexible
- Difficult to Query
- Slow to search
- Prone to anomalies
- Doesn’t support many-to-many relationships
Network Database Model
The network database model is similar to the hierarchical model. It was introduced in the late 1960s as a response to the inefficiencies of the hierarchical model. The major inefficiency solved by the network model was the many-to-many relationships that allowed for faster searches. This new efficiency was crucial for businesses.
For example, let’s look at the network model for a store:
A store has a manager, salespeople, and customers. The store is at the top of the structure because it encompasses the other data elements. The store is a parent element to customer, manager, and salespeople. Additionally, anyone of the three can make an order but only salespeople have access to the stores items.
Advantages of Network Model
- Easy to understand
- Business compatible
Disadvantages of Network Model
- Prone to anomalies
- Difficult to modify
Object-Oriented Database Model
The object-oriented database (OODB) model is similar to the relational model in that various tables represent real-life objects. However, similar or object-oriented programming (OOP) instances of objects can be created within the database.
Consider the following example of a student object:
The student object has four attributes, similar to the first example: a student ID, first and last name, and a student email address. This object acts as a template when creating instances of the object. The object instances are digital representations of a real-life object.
Additionally, unlike the relational model, the OODB model also supports data such as images. Considering these differences, OODB is often referred to as a hybrid model.
The entity-relationship database model is similar to the network model because it shows the relationship between two entities. However, the entity-relationship model or more detailed and allows for additional types of relationships, known as cardinality.
To be specific, these models can have one-to-one, one-to-many, or many-to-many relationship types. How the entities are related is also specified in the entity-relationship model.
Let’s look at the following entity-relationship:
This shows two entities, a student and a class. Entities are represented with a rectangle and the type of their relationship is represented with a diamond. The type of relationship will always be between the two entities.
Class and student also have a many-to-many cardinality represented by the ‘m’ and ‘n’ next to the entities. This represents that many students can take many classes at once.
Advantages of Entity-Relationship Model
- Great visual representation
- Simple to conceptualize
- Integrate with relational or other data models
Disadvantages of Entity-Relationship Model
- No industry standard for notation
- Data manipulation not represented
Which Database Model Is The Best?
Before choosing the model for your project, it will help to be clear on what exactly your building:
- How large is your project?
- How important is speed?
- How will the project scale?
- Will there be future enhancements?
No single database model will be the best option in every scenario. However, the relational database model is the most common model and meets most needs. In order to determine which model will work best for you, consider the advantages and disadvantages of each.