Database principle (4) ER model


The components of the ER model are entity sets, attributes and connection sets (one-to-one, one-to-many, and many-to-many), which can be represented by the ER model.

ER composition

The method of the ER model is as follows:

1. The entity set is represented by a rectangular box, and the entity name is written in the rectangular box.
2. The attribute of the entity is represented by a circle or an ellipse, and the attribute name is negotiated within the circle.
3. The connection between entities is represented by a prismatic box, the connection is named with an appropriate meaning, and the name is written in the diamond box, and the rectangular box of entities participating in the corresponding connection is connected to the diamond box with an undirected connection, and on the connection line Indicate the type of connection, namely 1:1, 1:M, N:M.

Insert picture description here

Representation of the connection between several special entities

  1. Represents the connection between three or more entity sets (multiple connections).
    For example, there are three entity sets: supplier, parts, and engineering, and the connection between them is "some suppliers provide certain parts for certain projects".
    Insert picture description here
  2. Express the connections within an entity set.
    The ER model allows the use of sub-bribery to represent the internal connections of a set of entities. As shown in the figure, the semantics are: one part in the part entity collection can be assembled from a variety of other parts, and one part can also be assembled and matched in a variety of parts.
    Insert picture description here
  3. Express any number of connections between two entity sets.
    The ER model can express multiple types of connections between two entities, including two-way connections. As shown in the figure, the semantics is: a project has multiple leaders (also staff), but a staff can only lead one project at most; work means that a project has multiple staff working for it, and a support can be in multiple projects jobs.
    Insert picture description here

ER model to relational model conversion

1. Conversion from ER model to relational model The
basic conversion rules are as follows:

1. Represent all entities and their attributes in the ER diagram with a relational framework (schema).
2. The relationship between the entities (the diamond box in the ER) and the related information in the two entities being contacted are also represented by a relationship frame.
Note:
(1) If the two entities are in a many-to-many relationship, the primary keywords of the relationship between the two entities are put into the contact relationship as the primary keyword (of course the relationship also includes some other useful additional information)
(2) If it is one-to-many, put the primary key in the "one" relationship into the "many" relationship as its foreign key, without the need to establish a relationship.

Insert picture description here
As shown in the figure above, the ER diagram can be converted into four relations:

  1. Student relationship S (student number, name, age, gender)
  2. Course relationship C (course number, course name, number of hours, teacher name)
    Note: One-to-many puts the teacher name in "one" in the course of "multi" as a foreign keyword
  3. Learning relationship R (student ID, course name, score)
    Note: Many-to-many puts the student ID and course name in the learning relationship as the main keywords.
  4. Teacher relationship T (name, age, job title)

In this way, a relational data model is obtained.

Guess you like

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