I know how to convert an entity set, relationship, etc. into the relational model but what i wonder is that what should we do when an entire diagram is given? How do we convert it? Do we create a separate table for each relationship, and for each entity set? For example, if we are given the following ER diagram:

My solution to this is like the following:

//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) )

My questions are:

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.

If my steps are not true or there is something i am missing, please can you write the steps for conversion? Also, what do we do if there is only participation constraint for a relationship, but no key constraint? Do we again create a single table for the related entity set and relationship?

I appreciate any help, i am new to databases and trying to learn this conversion.

Thank you

解决方案

Hi @bigO I think it is safe to say that your conversion is true and the steps that you have followed are correct. However from an implementation point of view, there may be room for improvement. What you have implemented is more of a logical model than a physical model

It is common practice to add a Surrogate Instance Identifier to a physical table, this is a general requirement for most persistence engines, and as pointed out by @Pieter Geerkens, aids database efficiency. The value of the instance id for example EmployeeId (INT) would be automatically generated by the database on insert. This would also help with the issue that @Pieter Geerkens has pointed out with the SSN. Add the Id as the first column of all your tables, I follow a convention of tablenameId. Make your current primary keys into secondary keys ( the natural key).

Adding the Ids then makes it necessary to implement a DependentPolicy intersection table

DependentPolicyId, (PK)

PolicyId,

DependentId

You may then need to consider as to what is natural key of the Dependent table.

I notice that you have age as an attribute, you should consider whether this the age at the time the policy is created or the actual age of the dependent, I which case you should be using date of birth.

Other ornamentations you could consider are creation and modified dates.

I also generally favor using the singular for a table ie Employee not Employees.

Welcome to the world of data modeling and design.

er图转换成关系模型的例题,将ER图转换为关系模型相关推荐

  1. er图转换成关系模型的例题_有关数据库系统的练习题 E-R图的关系画图转换,,急需 谢谢了...

    展开全部 你看62616964757a686964616fe58685e5aeb931333332643239下下边的例子,你的问题就可以解决了. 设某商业集团数据库中有三个实体集.一是"商 ...

  2. er图转关系模式规则_ER图转换成关系模式集的规则[图]

    ER图转换成关系模式集的规则[图] 08-18栏目:技术 TAG:关系模式 关系模式 转自己博客园文章 www.jhua.org copyright www.jhua.org A与B=1:1 在A表里 ...

  3. 如何将实体关系图转换成关系模式

      一个实体转换成一个关系模式. 首先,通过visio绘制一个与学生实体有联系的几个E-R图.如下图所示 其中矩形表示的是实体(班级,学生,课程,学习账号),椭圆表示的是属性,菱形表示的是联系(拥有, ...

  4. 【突破二次元壁】手把手教你用AnimeGAN将风景图转换成宫崎骏动漫风

    [突破二次元壁!]手把手教你用AnimeGAN将风景图转换成宫崎骏动漫风! 未经作者允许,本文禁止转载 0. 效果图: 1. 下载源码: 2. 下载预训练模型: 3. 准备图片: 4. 开始转换: 5 ...

  5. 一幅RGB彩色原图和其三个分量的显示,RGB图转换成HSI的显示

    数字图形处理实验记录 实验一 :一幅RGB彩色原图和其三个分量的显示,RGB图转换成HSI的显示 转换原理:采用圆锥模型公式 测试步骤: Matlab转化函数: function HSI = RGB2 ...

  6. Intel Realsense D435 opencv 为什么将color图转换成灰度图后,再与depth图水平堆叠,其结果一片黑色?(数据未map到0-255)

    相关代码 # -*- coding: utf-8 -*- """ @File : obstacle_detection.py @Time : 2019/12/11 10: ...

  7. 灰度图转换成彩色图和彩虹图

    把灰度图转换成彩色图和彩虹图 1. 灰度图转换成彩色图 void Gray2Color(const cv::Mat const &src, cv::Mat &dst){     dst ...

  8. html视频怎么转换成图片,如何将小视频转换成GIF动图或将GIF动图转换成视频

    现在GIF动图是越来越流行了.在过去,它是我们在Web上唯一能展示动画图片的技术.这种技术非常的有用,因为,相对于Real Video Player, Windows Media等技术,都需要特殊的浏 ...

  9. matlab将图片转成eps,【MATLAB】论文图片处理(各种数据图转换成eps格式)

    最近跟eps图片杠上了..转载一个人人网上matlab到eps图片输出格式较好的方法 随着Latex在论文编辑和排版的日益普及,越来越多的人写文章都用Latex,数据图表作为论文不可缺少的一部分,如何 ...

  10. matlab eps格式,【MATLAB】论文图片处理(各种数据图转换成eps格式)

    最近跟eps图片杠上了..转载一个人人网上matlab到eps图片输出格式较好的方法 随着Latex在论文编辑和排版的日益普及,越来越多的人写文章都用Latex,数据图表作为论文不可缺少的一部分,如何 ...

最新文章

  1. 坑爹系列1--Log
  2. Java项目:学生信息管理系统(java+SSM+jsp+mysql+maven)
  3. AngularJS学习笔记(二) 表单验证案例(ng-repeat/filter)
  4. iframe子页面点击按钮,执行父页面的点击事件
  5. axis2+myeclipse6.5环境搭建
  6. 销售员/学员/讲师系统
  7. 计算机检索技术与技巧的检索式为,第四章计算机检索技术和数据库检索方式.ppt...
  8. (24)css3盒子阴影
  9. ASIHTTPRequest報錯解決辦法
  10. 【高德地图】------- JavaScript实现高德地图经纬度获取地址位置
  11. 默认关闭IDEA的注释doc的rendered view模式
  12. 为什么说龙妈能活到最后?
  13. Qt开发经验总结之武林秘籍
  14. MPLS中的标签信息库LIB和标签转发信息库LFIB + RIB/FIB + ARP/FDB + CAM/TCAM
  15. su vs sudo的区别
  16. 数据分析实习代码总结【进阶】Python
  17. 离散数学图论经典问题之握手定理
  18. C++实现黑白棋算法
  19. 一台服务器 运行虚拟机吗,(原创)关于一台服务器能安装多少台虚拟机问题?...
  20. Oracle函数——比较函数

热门文章

  1. python勿使用mutable值作为默认参数
  2. Summed-Area Variance Soft Shadow Mapping(SAVSM):一
  3. 混合使用Objective-C,C++和Objective-C++
  4. UE4 控制台管理器: 在C++中设置控制台变量
  5. javascript基础学习
  6. 聊聊数据权限哪些事儿
  7. MySQL级联复制(A-B-C) —log-slave-updates = 1
  8. 如何实现红帽企业虚拟化管理平台Host主机所在数据中心的切换
  9. 男性最脆弱的五大器官
  10. pda连接电脑无法存取文件_手机无法连接电脑怎办