我知道如何将实体集、关系等转换为关系模型,但我想知道的是,当给出整个图表时我们应该怎么做?我们如何转换它?我们是否为每个关系和每个实体集创建一个单独的表?例如,如果我们得到以下 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.
如果我的步骤不正确或者我遗漏了什么,请你写下转换的步骤吗?另外,如果一个关系只有参与约束,而没有关键约束,我们该怎么办?我们是否再次为相关实体集和关系创建单个表?
我很感激任何帮助,我是数据库新手,正在尝试学习这种转换。
谢谢