數據庫——由ER圖轉換爲關係映射的方法

數據庫——由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.

發佈了162 篇原創文章 · 獲贊 40 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章