Traditional Culture Encyclopedia - Traditional festivals - The commonly used data models of database management system include hierarchical model, grid model and what?

The commonly used data models of database management system include hierarchical model, grid model and what?

There are three common data models in database management system: hierarchical model, grid model and relational model.

Data model is a simulation of real-world data and a research tool. With this research tool, we can better abstract real things into data that computers can process.

Hierarchical model: hierarchical model uses "tree structure" to represent the relationship between data.

Hierarchical model is the earliest model used in database system, and its data structure is a "directed tree". The root node is at the top, with the highest level, and the child nodes are at the bottom, arranged layer by layer.

The hierarchical model is characterized by:

The constraints in the hierarchical model are:

(1) has only one node and no parent node, which is the root of the tree; (One and only one node has no parent node, which is the root node. )

(2) Other nodes have only one parent node. (Other nodes except the root have one and only one parent node.

This makes the hierarchical database system only deal with one-to-many entity relationships directly.

(3) Any given record value can only show its full meaning if it is viewed according to its path, and no child record value can exist independently of the parent record value.

For example, the hierarchical model of teachers and students. There are four record types in hierarchical model, namely entity.

They are:

(1) The record type (entity) system is the root node and consists of number, name, specialty and headcount attributes (fields). It has two sub-nodes, namely, college teacher entity and curriculum entity.

(2) The record (entity) teacher is a sub-node of the college, which consists of six attributes (fields).

(3) The recorded (entity) course consists of four attributes (fields).

(4) Documentary (physical) teachers are composed of six attributes (fields). Courses and teachers are leaf nodes, colleges and teachers, and teachers and courses have a one-to-many relationship.

data integrity contraints

It has four main functions: add, delete, check and modify; Meet the integrity constraints;

Add (insert): to meet the requirements, there must be a parent node, that is, if you join a teacher, you must be assigned to a college;

Delete: if it is a byte point, it will not affect, and the byte point will be deleted directly; If it is a parent node, delete the whole byte point; If the whole teaching and research section is deleted, the teachers in the teaching and research section will not have this system;

Search: search from top to bottom according to the tree structure;

Modify: Update the information of the corresponding relationship.

Its advantages and disadvantages:

Advantages:

Relatively simple and easy to use;

The structure is clear, and companies and families in reality have similar structures;

Good integrity support;

The query efficiency is high, the model level is targeted, and the access path is often recorded.

Disadvantages:

Many relationships are not one-way, one-to-many, many-to-one, and can only be solved by introducing redundant data or establishing virtual nodes and other unnatural data organizations, which are prone to inconsistency;

There are too many restrictions on inserting and deleting.

The lookup byte point must pass through the parent node;

The attribute of any record in the tree node is a simple data type and cannot be subdivided;

Grid model: the grid model uses "graph structure" to represent the relationship between data.

1, conditional characteristics

(1) Allow multiple nodes without a parent node.

(2) At least one node can have multiple parent nodes.

In the grid model, each node represents a record type (entity), and each record type can contain several fields (attributes of the entity). Connecting lines between nodes represent the parent-child relationship between record types (entities).

As can be seen from the definition, the relationship between the child node and the parent node in the hierarchical model is unique, but it may not be unique in the grid model. Therefore, in the grid model, we should name each contact and point out the parent record and child record related to the contact.

2. Representation method:

Entity Type: described by the record type.

Each node represents a record type (entity);

Attribute: described by fields, and each record type contains several fields;

Connection: the one-to-many parent-child relationship between record types (entities) is represented by connecting lines between nodes;

The difference between mesh model and hierarchical model;

Grid model: multiple nodes without parent nodes are allowed;

Allow a node to have multiple parent nodes;

Allow two nodes to have multiple connections (composite connections);

Can describe the real world more directly;

Hierarchical model is a special case of grid model.

Give each contact a name (L 1, L2), and indicate the parents' records and children's records related to the contact.

3. Representation of many-to-many network model

Representing many-to-many relationship with grid model

Methods: Many-to-many was directly decomposed into one-to-many connections.

4. Example: Student Course Selection Model

It consists of three data items: student number, course number and grade, indicating that a student has taken a certain course and its grade.

Each student can take multiple courses. Obviously, for a value in the student record, there can be multiple values associated with it in the course selection record. However, the value in the course selection record can only be related to the value in the student record. The relationship between students and course selection is a one-to-many relationship, which is called student course selection. Similarly, the relationship between courses and course selection is one-to-many, which is called course-course selection.

Step 5 manipulate

The data operation of grid model mainly includes query, insertion, deletion and update:

Insert: insert the child node value whose parent node value is not determined;

Delete: Only the parent node value can be deleted. For example, you can delete a teaching and research room, and all the teachers' information in the research room is kept in the database.

Modify: it can directly represent the non-tree structure without adding redundant nodes like the hierarchical model, so when modifying, you only need to specify the update record.

Network data system (DBTG) imposes some restrictions on data and provides some integrity constraints:

Code: a collection of data items that uniquely identify records;

Parents' records and children's records are one-to-many in a contact;

Support some binding conditions between parent records and child records;

Key: realize record contact;

Common methods: one-way, two-way, loop and head-to-head link;

6. Advantages and disadvantages

The advantages of the grid data model are as follows:

(1) can describe the real objective world more directly, and can represent various complex relationships between entities.

(2) Good performance and high access efficiency.

The disadvantages of the grid data model are as follows:

The structure of (1) is complicated, and its data definition language (DDL) and data manipulation language (DML) are complicated, which makes it inconvenient for users to use. Moreover, the larger the application environment, the more complex the database structure, which is not conducive to the end user to master.

(2) Poor data independence. Because the relationship between entities is essentially represented by access paths, applications should specify access paths when accessing data.

Relational model: Relational model uses "two-dimensional table" (or relationship) to represent the relationship between data.

1, basic terms

(1) relationship: a relationship corresponds to a two-dimensional table, and the two-dimensional table is the relationship name.

(2) Tuple: A row in a two-dimensional table is called a tuple.

(3) Attribute: A column in a two-dimensional table is called an attribute. The number of attributes is called the degree of elements or relationships. The value of the column is called the attribute value;

(4) (Value) domain: the value range of the attribute value is the value domain.

(5) Component: the attribute value of the column corresponding to each row, that is, an attribute value in the tuple. [2]

(6) Relational mode: the row definition in the two-dimensional table, that is, the description of the relationship, is called relational mode. Generally expressed as (attribute 1, attribute 2, ..., attribute n), for example, the relationship model of teachers can be expressed as teachers (teacher number, name, gender, age, professional title, department).

(7) Key (code): If there is an attribute or attribute set that uniquely identifies an entity in a relationship called the key of the entity, then even if there are two tuples in any relationship state of the relationship, the combination of values on the attribute is different.

(8) Candidate key (candidate code): If the value of an attribute in the relationship can uniquely identify a tuple, if any attribute cannot be deleted from a key of the relationship, it is not the key of the relationship, then the specified candidate key is called the candidate key or candidate code of the relationship.

For example, if both the student ID and the library ID in the following student table can uniquely identify a tuple, then both the student ID and the library ID can uniquely identify a tuple, and then both the student ID and the library ID can be used as candidate keys for student relations.

In the course selection table, only the attribute groups "student number" and "course number" can uniquely identify a tuple, so the candidate key is (student number, course number).

2. Data manipulation and integrity constraints of relational model.

The operations of relational data model mainly include querying, inserting, deleting and modifying data; These operations must satisfy the integrity constraints of the relationship.

The characteristic of data operation in relational model is set operation mode, that is, both the operation object and the operation result are sets, also known as one set at a time.

Accordingly, the operation mode of the non-relational data model is one record at a time.

The integrity constraints of relationships include three categories:

Entity integrity, referential integrity and user-defined integrity.

Entity integrity defined the conditions that the master code of every basic relationship in the database should meet, which can ensure the uniqueness of tuples. Referential integrity defines the referential relationship between tables, that is, the relationship between references and references. User-defined integrity is a data rule formulated by users for a specific application environment, which reflects the semantic requirements that the data involved in a specific application must meet.

3. Advantages and disadvantages of relational model

superiority

(1) relational model is different from non-relational model, which is based on strict mathematical theory.

(2) The concept of relational model is single, the relationships between entities are expressed by relationships, and the retrieval results of data are also relationships (tables), so its data structure is simple and clear, which is easy for users to understand and use.

(3) The physical storage and access paths of the relational model are transparent to users, so it has higher data independence, better security and confidentiality, and simplifies the programmer's database development work.

disadvantaged

(1) Because the access path is transparent to users, the query efficiency is often not as high as that of the non-relational data model. Therefore, in order to improve the performance, users' query requests must be optimized, which increases the difficulty and burden of developing database management system.

(2) Relational data model can't naturally represent the relationship between entity sets, and it has some weaknesses such as insufficient semantic information and too few data types.