er模型转关系模式_ER模型到关系模型

er模型转关系模式

ER模型到关系模型 (ER Model to Relational Model)

As we all know that ER Model can be represented using ER Diagrams which is a great way of designing and representing the database design in more of a flow chart form.

众所周知,ER模型可以使用ER Diagrams表示,这是一种设计和表示数据库设计的好方法,更多地采用流程图形式。

It is very convenient to design the database using the ER Model by creating an ER diagram and later on converting it into relational model to design your tables.

使用ER模型设计数据库非常方便,方法是创建一个ER图,然后将其转换为关系模型以设计表。

Not all the ER Model constraints and components can be directly transformed into relational model, but an approximate schema can be derived.

并非所有的ER模型约束和组件都可以直接转换为关系模型,但是可以导出近似模式。

So let's take a few examples of ER diagrams and convert it into relational model schema, hence creating tables in RDBMS.

因此,让我们以ER图的一些示例为例,并将其转换为关系模型架构,从而在RDBMS中创建表。

实体成为表格 (Entity becomes Table)

Entity in ER Model is changed into tables, or we can say for every Entity in ER model, a table is created in Relational Model.

ER模型中的实体已更改为表,或者可以说,对于ER模型中的每个实体,都会在关系模型中创建一个表。

And the attributes of the Entity gets converted to columns of the table.

实体的属性将转换为表的列。

And the primary key specified for the entity in the ER model, will become the primary key for the table in relational model.

并且在ER模型中为实体指定的主键将成为关系模型中表的主键。

For example, for the below ER Diagram in ER Model,

例如,对于下面的ER模型中的ER图,

ER model to Relational - Entity to Table

A table with name Student will be created in relational model, which will have 4 columns, id, name, age, address and id will be the primary key for this table.

将在关系模型中创建一个名称为Student的表,该表将有4列, idnameageaddressid将是该表的主键。

关系成为关系表 (Relationship becomes a Relationship Table)

In ER diagram, we use diamond/rhombus to reprsent a relationship between two entities. In Relational model we create a relationship table for ER Model relationships too.

在ER图中,我们使用菱形/菱形表示两个实体之间的关系。 在关系模型中,我们也为ER模型关系创建关系表。

In the ER diagram below, we have two entities Teacher and Student with a relationship between them.

在下面的ER图中,我们有两个实体TeacherStudent ,它们之间具有关系。

ER diagram relationship into table in rdbms

As discussd above, entity gets mapped to table, hence we will create table for Teacher and a table for Student with all the attributes converted into columns.

如上所述,实体被映射到表,因此我们将为教师创建表,为学生创建表,并将所有属性转换为列。

Now, an additional table will be created for the relationship, for example StudentTeacher or give it any name you like. This table will hold the primary key for both Student and Teacher, in a tuple to describe the relationship, which teacher teaches which student.

现在,将为该关系创建一个附加表,例如StudentTeacher或为其指定任何您喜欢的名称。 该表将在一个元组中包含“学生”和“老师”的主键,以描述这种关系,由哪个老师教给哪个学生。

If there are additional attributes related to this relationship, then they become the columns for this table, like subject name.

如果还有与此关系相关的其他属性,则它们将成为此表的列,例如主题名称。

Also proper foriegn key constraints must be set for all the tables.

还必须为所有表设置适当的前键约束。

要记住的要点 (Points to Remember)

Similarly we can generate relational database schema using the ER diagram. Following are some key points to keep in mind while doing so:

同样,我们可以使用ER图生成关系数据库架构。 以下是在执行此操作时要记住的一些关键点:

  1. Entity gets converted into Table, with all the attributes becoming fields(columns) in the table.

    实体被转换成表格,所有属性变成表格中的字段(列)。
  2. Relationship between entities is also converted into table with primary keys of the related entities also stored in it as foreign keys.

    实体之间的关系也转换为表,同时相关实体的主键也作为外键存储在表中。
  3. Primary Keys should be properly set.

    应该正确设置主键。
  4. For any relationship of Weak Entity, if primary key of any other entity is included in a table, foriegn key constraint must be defined.

    对于弱实体的任何关系,如果表中包含任何其他实体的主键,则必须定义前键约束。

翻译自: https://www.studytonight.com/dbms/er-to-relational-model.php

er模型转关系模式