Working with hierarchical data models

1. Working with hierarchical data models

Up to now, we have been querying hierarchical data models, but we haven't seen how they are created and why they are representing a hierarchy. In this last video, we will learn how to create a hierarchical data model. Furthermore, we will also learn about networked data models, which are a variation of hierarchical data models.

2. The hierarchical data model

For our purposes, the most important data model is the hierarchical data model. A possible representation of a hierarchy is shown on the slide. A hierarchical database model has some properties. The first one is that a hierarchy can be represented by a tree. Accordingly, a hierarchical data model has one root element and each child element can only have one parent element. When looking at the advantages, we can see that hierarchical data models are easy to understand and to select. But these data models also have some disadvantages. The structure is fixed and therefore, complicated to be modified.

3. Example of hierarchical data model

A possible example of this type of data model is the customer bill article relation. The idea is that one customer can have several bills and each bill can have several articles. So the customer can have bill 1 and on this bill, there are articles 1 and 2. A possible way to model this problem is to create three tables. One is the table costumer with a customerID. A second table is bill with the billID and the customerID of the first table and a third table Article with the articleID and the billID of the second table.

4. The networked data model

Another example of a hierarchical database model is the networked data model. For this database model, we have a many to many relation. Many children records can have many parents records. Accordingly, we can have several selection possibilities to find a possible path. In contrast, for a hierarchical data model, we can have only one search path. The use of networked data models is beneficial because it is not as strict as the structure of a hierarchical model. We have many solution paths and can find many real-world examples. A disadvantage is if the data model increases and is big, the clarity decreases.

5. Example of networked data models

An example for a networked database model is the customer-order-article relation. In this database model, many customers can have several orders and for each order, a selection of articles. We can see in the image that customer 1 has the two orders, order 1 and order 2. Order 1 contains article 2 and order 2, article 1 and 3. The data model shown here is a networked data model, because one article can be selected more than once. For example, article 2 is purchased in both order 1 and 3. This is also the difference with the hierarchical data model, where the bill could only have one relation with the article that was purchased. This problem could be defined by three tables and references from one table to the other table. The difference here is for the networked data model, it is possible to have two orders referencing one article, which would not be possible for a hierarchical data model.

6. Let's practice!

Now you know how hierarchical and networked data models are created and have learned about their differences and why they are beneficial. In the following exercises, you will create hierarchical and networked data models.