1. 分层数据模型:
分层数据模型是最古老的数据模型类型。它由 IBM 于 1968 年开发。它以树状结构组织数据。分层模型包括以下内容:
- 它包含由分支连接的节点。
- 最顶层的节点称为根节点。
- 如果有多个节点出现在顶层,那么这些可以称为根段。
- 每个节点只有一个父节点。
- 一位家长可能有多个孩子。
在上图中,Electronics 是根节点,它有两个子节点,即 TV 和 Portable Electronics。这两个有更多的孩子,他们作为父母。例如:Television 有Tube、LCD 和Plasma 子项,因为这三个Television 充当父项。它遵循一对多的关系。
2. 关系数据模型:
关系数据模型由 EF Codd 于 1970 年开发。它们没有物理链接,因为它们处于分层数据模型中。以下是关系数据模型的属性:
- 数据仅以表格的形式表示。
- 它只处理数据而不处理物理结构。
- 它提供有关元数据的信息。
- 在行和列的交叉处,元组将只有一个值。
- 它提供了一种轻松处理查询的方法。
分层和关系数据模型之间的区别:
Hierarchical Data Model |
Relational Data Model |
---|---|
In this model, to store data hierarchy method is used. It is oldest method. | It is the most flexible and efficient database model. It is most used database in today. |
It implements 1:1 and 1:n. | In addition to 1:1 and 1:n it also implements many to many relationships. |
To organize records, it uses tree structure. | To organize records, it uses table. |
More chances of complexity. | No chance of complexity. |
There is lack of declarative query facility. In current times they are being modelled using NoSQL | It provides facility of declarative query facility using SQL. |
Records are linked with help of pointers. | Records are linked with help of rows and columns. |
Insertion anomaly exits in this model i.e. child node cannot be inserted without parent node. | There is no insertion anomaly. |
Deletion anomaly exists in this model i.e. it is difficult to delete parent node. | There is no deletion anomaly. |
It is used to access data which is complex and asymmetric. | It is used to access data which is complex and symmetric. |
This model lacks data independence. | This model provides data independence. |
This design is used in modern times for faster access of data. This is obtained by trade offs i.e. on giving up on redundancy where the levels(parents to child) are relatively less. | Due to many to many to many relationship joins take a heavy toll on search with multiple parameter query |
Currently this model is being used in shopping carts and search engine. There are tools that can emulate hierarchical database e.g. Mangodb, firebase | Most of the traditional software are using relational database common e.g. Oracle dB, MS sql server, IBM DB2 |