数据库——由ER图转换为关系映射的方法

来源:互联网 发布:国外的即时通讯软件 编辑:程序博客网 时间:2024/04/19 17:50

数据库——由ER图转换为关系映射的方法


具体步骤:

1.For each strong entity type E. Create a new table. Include as its columns, all the simple attributes and simple components of the composite attributes of E. Identify the primary key and the alternate keys. Do not include any multi-valued attribute as a key. If the only unique field of an entity is a multi-valued attribute, introduce an artificial primary key field.

强实体类型的映射:实体E转换成关系R,R中包含有中所有的简单属性。对于复合属性,将其复合转换成简单属性

2.For each weak entity W that is associated with only one 1:1 identifying owner relationship. Identify the table T of the owner entity type. Include as columns of T, all the simple attributes and simple components of the composite attributes of W.

3.For each weak entity W that is associated with a 1:N or M:N identifying relationship, or participates in more than one relationship. Create a new table T. Include as its columns, all the simple attributes and simple components of the composite attributes of W. Form the primary key of T as follow: In the case of a 1:N owner relationship, by including as a foreign key in T, the primary key of the owner entity. The primary key of T is the combination of W’s partial key and the foreign key. In the case of a M:N owner relationship, by creating a new column that will hold unique values. (In this case, the association between the weak entity and its owner entity will be specified in Step 6.)

4.For each binary 1:1 relationship type R. Identify the tables S and T of the participating entity types. Choose S (preferably the one with total participation). Include as foreign key in S, the primary key of T. Include as Columns of S, all the simple attributes and simple components of the composite attributes of R.

二元关系1:1的映射:实体A和B为1:1,两个实体分别对应的关系为R和S,在关系R中使用S的主键为外键,在S中使用R的主键为外键。

5.For each binary 1:N relationship type R. Identify the table S (at the N-side) and T of the participating entities. Include as a foreign key in S, the primary key of T. Include as columns of S, all the simple attributes and simple components of composite attributes of R.

二元关系1:N的映射。实体A和B为1:n,两个实体分别对应的关系为R和S,标示S为n的一端,在S中使用R为外键,主键为S的主键。

6.For each N-ary relationship (including binary N:M relationship) type R. Create a new table T. Include as columns of T, all the simple attributes and simple components of composite attributes of R. Include as foreign keys, the primary keys of the participating (strong or weak) entity types. Specify as the primary key of T, the list of foreign keys.

二元关系M:N的映射。实体A和B为m:n,两个实体分别对应的关系为R和S,则为M:N创建一个新的关系T,在T中使用R和S的主键的组合为T的主键

7.For each multi-valued attribute A. Create a new table T. Include as columns of T, the simple attribute or simple components of the attribute A. In table T, include as foreign key, the primary key of the entity or relationship type that has A. Specify as the primary key of T, the foreign key and the columns corresponding to A.

多值属性A的映射。为每个多值属性创建一个新的关系R。R中包含A相对应的一个属性,另外还包括该A所在实体的主键K。R的主键由A,K的组合

8.For each specialization with disjoint subclasses. Create a new table Ti for each subclass Si. Include as columns of Ti, the simple attributes and simple component attributes of the superclass. Include as columns of Ti, the simple attributes and simple component attributes specific to Si. Identify the primary key.

9.For each specialization with overlapping subclasses. Create a new table O for the superclass. Include as columns of O, the simple attributes and the simple component attributes of the superclass. Identify its primary key and alternate keys. Create a new table Ti for each subclass Si. Include as columns of Ti, the simple attributes and simple component attributes specific to Si. Include as a foreign key in Ti (to be part of the primary key of Ti), the primary key of O.

0 0
原创粉丝点击