Database Principle (3) Three Data Models

Hierarchical data model

A tree or forest structure is used to represent the model of the entity and the relationship between the entities. The entity is represented by the nodes in the tree, and the relationship between the entities (only one-to-many) is represented by the lines in the tree.

  • Hierarchical model refers to a collection of basic hierarchical connections that meet the following conditions.
    (1) There is one and only one node without a parent node, this node is the root of the tree
    (2) Other nodes other than the root node have one and only one parent node

Insert picture description here
As shown in the figure: (1) The root of the tree is the factory (2) The parent and child nodes of each layer are one-to-many.
A factory can have multiple branches, a branch can have multiple workshops, and a workshop can have multiple teams.

Characteristics of Hierarchical Data Model

  1. The hierarchical tree in the hierarchical model is an ordered tree, that is, for the hierarchical model, the order of all subtrees of any node is specified in the order from left to right. This also implies a control over the access path of the hierarchical database
  2. The relationship between entities in the tree is one-way, that is, from the parent node to the child node, and there is more than one relationship between a pair of parent and child nodes, that is, for any node in the tree, there is only one root. The path the node takes to reach it.
  3. The relationship in the hierarchical model can only be the one-to-many relationship between the parent node and the child node, which also limits the direct expression of the many-to-many relationship in the hierarchical data model.
  4. Any attribute of any record in the tree node is simple data that cannot be divided, that is, atomic.

Method of converting to hierarchical tree structure

  1. Convert the many-to-many relationship to a hierarchical structure
    . Except for the root node in the hierarchy, the record in any node can only correspond to one record in the parent node, and one record in a node can have a child node Corresponding to multiple records. To solve the many-to-many problem is to use two one-to-many, for example, students and teachers, they have a many-to-many relationship. The first one-to-many takes the teacher parent node and the student as the child node. The second one takes the student as the parent node and the teacher as the child node. In this way, a many-to-many relationship can be expressed.
  2. Convert the non-tree network structure to a hierarchical structure
    (1) Introduce redundant nodes
    , that is, nodes can be repeated (repetition is redundant), so that all nodes appear in the tree structure. First take the node without the parent node as the root of the tree, and then find the corresponding child node.
    Insert picture description here
    Advantages: clear structure, allowing changes in node storage locations.
    Disadvantages: It takes up more storage space and it is more difficult to maintain data consistency.
    (2) Introducing a virtual node
    The process is the same as that of a redundant node, except that the node that has already appeared is not replaced by a copy, but is replaced by a virtual node. The virtual node is a pointer to the replaced node.

Mesh data model

The network structure represents the model of entity types and their connections. As the name implies, one thing is related to several others, which constitutes a network diagram. That is, there is only one node without a parent node, and all other nodes except the root node have one and only one parent node, and there is only one one-to-many relationship between two nodes. In layman's terms, all nodes are not repeated and are directly connected to those related to themselves.

  • The hierarchical model is actually a special case of the mesh model. The mesh model needs to meet the following conditions .
    (1) There is only one node without a parent node.
    (2) All nodes except the root node have one and only one parent node.
    (3) There is only a one-to-many relationship between two nodes.Insert picture description here

Relational data model

Simply put, a model that uses two-dimensional table data to represent the relationship between entities and entities is called a relational data model.
Insert picture description here

  • Some terms in the relational model :
    (1) Relation: a relation corresponds to a table in general;
    (2) Tuple: a row in the table is a tuple;
    (3) Attribute: a column in the table is a table Attribute, give each attribute a name, that is, the attribute name;
    (4) Code: also known as the code key, a certain attribute group in the table, it can uniquely determine a tuple;
    (5) Domain: a group with the same data A collection of values ​​of type. The value range of the attribute comes from a certain domain;
    (6) Component: an attribute value in the tuple.
    (7) Relationship mode: the description of the relationship, which is expressed as: relationship name (attribute 1, attribute 2, ..., attribute n)

Characteristics of the relational model

(1) A relationship is a collection of tuples, and the order of each tuple in the relationship is irrelevant.
(2) Each attribute of the relationship is an indivisible basic data type, that is, the value in each row and column position in the two-dimensional table of the relationship is an atomic value, and cannot be a set tuple or a combination of them. That is, it satisfies the first normal form
(3) allows the attribute value to be null,
(4) any two tuples (rows) of the same relationship are not allowed to be identical, that is, if the relationship is a set of tuples, there cannot be the same element Group (row).

Comparison of the three data models

  1. Relational data model
    Advantages:
    (1) It can express various entities and their connections simply and flexibly.
    (2) Good user interface and best ease of use.
    (3) Support database reconstruction.
    (4) It has a strict mathematical foundation and algebraic nature of operation.
    (5) Have high data independence.
    (6) It is closely related to first-order predicate logic in theory.
    Disadvantages:
    (1) The operation efficiency is not high.
    (2) Does not support hierarchical structure, so it does not directly support the modeling of concepts such as generalization and aggregation, is not suitable for managing complex objects, and has weak semantic modeling capabilities.
  2. Hierarchical data model
    Advantages:
    (1) It can directly simulate many applications with natural hierarchical structure in the real world. It directly supports the modeling of concepts such as generalization and aggregation.
    (2) High operating efficiency.
    Disadvantages:
    (1) The user interface is not friendly enough.
    (2) Many-to-many relations cannot be expressed directly, and the modeling conversion of many-to-many relations may cause redundancy in physical storage
    (3) Poor data independence
    (4) Basically lack of operational algebra basis and deductive functions
  3. Net data model
    Advantages:
    (1) Easy to express many-to-many relationship.
    (2) Has certain data independence and sharing characteristics
    (3) High operating efficiency
    Disadvantages:
    (1) User interface is not friendly enough
    (2) Complex structure
    (3) Basically does not have the basis of operation algebra and deductive function
    (4) For hierarchical structure The expression is not natural and direct.

Guess you like

Origin blog.csdn.net/qq1350975694/article/details/107179320