我知道如何將實體集,關係等,轉換成關係模型,但讓我感到奇怪的是,我們應該做些什麼時,給出一個完整的圖?我們如何轉換它?我們是否爲每個關係和每個實體集創建一個單獨的表?例如,如果我們給出下面的ER圖:轉換ER圖向關係模型
我對這個解決方案是這樣的:
//this part includes the purchaser relationship and policies entity set
CREATE TABLE Policies (
policyid INTEGER,
cost REAL,
ssn CHAR(11) NOT NULL,
PRIMARY KEY (policyid).
FOREIGN KEY (ssn) REFERENCES Employees,
ON DELETE CASCADE)
//this part includes the dependents weak entity set and beneficiary relationship
CREATE TABLE Dependents (
pname CHAR(20),
age INTEGER,
policyid INTEGER,
PRIMARY KEY (pname, policyid).
FOREIGN KEY (policyid) REFERENCES Policies,
ON DELETE CASCADE)
//This part includes Employees entity set
CREATE TABLE Employees(
ssn Char(11),
name char (20),
lot INTEGER,
PRIMARY KEY (ssn))
我的問題是:
1)Is my conversion true?
2)What are the steps for converting a complete diagram into relational model.
Here are the steps that i follow, is it true?
-I first look whether there are any weak entities or key constraints. If there
are one of them, then i create a single table for this entity set and the related
relationship. (Dependents with beneficiary, and policies with purchaser in my case)
-I create a separate table for the entity sets, which do not have any participation
or key constraints. (Employees in my case)
-If there are relationships with no constraints, I create separate table for them.
-So, in conclusion, every relationship and entity set in the diagram are included
in a table.
如果我步驟是不正確的或有缺少的東西,請你能寫出轉換的步驟?另外,如果只有關係的參與約束,但沒有關鍵約束,我們該怎麼辦?我們是否再次爲相關的實體集和關係創建單個表?
我感謝所有幫助,我是新來的數據庫,並努力學習這種轉換。
謝謝
不要讓SSN成爲員工的主鍵!他們重新使用〜死後6個月。他們也可以在特定的情況下(例如獲得公民權)改變某個特定的人。 – 2013-04-08 22:33:40
@PieterGeerkens,但爲什麼?在ER圖中,ssn被認爲是員工的關鍵? – yrazlik 2013-04-08 22:36:07
另外,認識到物理模型中的主鍵約束不是概念設計中主鍵約束的精確實現。PM中的PK是(a)更新記錄的物理表示的手段;和(b)相關表格有效地驗證物理記錄的存在並附於其上的句柄。作爲物理模型的一個主要目標是效率,使得PM中的PM短是一個重要的設計標準;它在概念設計中是無關緊要的。 – 2013-04-08 22:42:24