栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

数据库实体关系模型 --- ER Model

数据库实体关系模型 --- ER Model

数据库实体关系图 --- The Entity-Relationship Model: ER Model
  • ER模型的基本组成
  • E-R diagram的基本组成
    • Constraints
      • Key constraints
      • Participation Constraints
    • Keys
      • 超码: superkey
      • 候选码: candidate key
      • 主键: primary key
      • 外键 foreign key
      • 弱实体 weak entity set
    • 实体(entity)的继承
  • 设计ER需要考虑的因素
    • 实体集 or 属性 (Entity set or Attribute)
    • 三元 or 二元 (Binary or Ternary)

ER模型的基本组成
  • 实体(entity): 最基本的数据成员,An entity is an object that exists and is distinguishable from other objects
  • For instance, Michelle Lee with S.S.N.890-12-3456 is an entity
  • 一个entity可以是concrete(一个人,一本书等) 也可以是abstract (比如假期或者疾病)
  • entity set:一组同一类型的entities组成了entity set
  • 比如银行的所有用户组成了一组entity set
  • entity set可以有重叠,比如Student 和 Professor这两个entity set可以有重复的entity,因为一个人可以是老师也可以是另外一节课的学生
  • 属性(attributes): 一个entity用一组attributes来表示,每一个attribute有一个对应的值,比如一个人可以有name,SSN,gender,phone number等attributes
  • domain: 一个attribute的domain是这个attribute值得有效范围,比如电话号码是一个十一位整数
E-R diagram的基本组成
  • 我们可以通过E-R diagram 来描述一个数据库的逻辑结构
  • ER diagram 的基本组成结构有
  • 正方形 — 代表entity sets
  • 椭圆形 — 表示attributes
  • 菱形 — 表示relationship sets
  • 线条 — 链接attributes和entity sets,entity sets和relationship sets
Constraints Key constraints
  • One-to-one: A中的entity最多和一个B中的entity链接, B中的entity最多和一个A中的entity链接
  • One-to-many: A中的entity可以和很多个B中的entity链接, B中的entity最多和一个A中的entity链接
  • Many-to-one: A中的entity最多和一个B中的entity链接, B中的entity可以和很多个A中的entity链接
  • many-to-many: A中的entity可以和很多个B中的entity链接, B中的entity可以和很多个A中的entity链接
  • Example: many-to-one constraints
  • 一个指导老师可以指导很多学生,但是一个学生只能有一个指导老师
  • 我们可以用箭头表示这种关系
  • 箭头指向的是one
  • Example: one-to-one constraints
  • 一夫一妻就是one-to-one constraints
  • Example: one-to-many constraints
  • 一个母亲有很多孩子
  • Example: many-to-many constraints
  • 男生有很多女同学,女生也有很多女同学
Participation Constraints
  • total participantion:假如现在要创建一个 某市已婚人士 的数据库,则每个entity的participantion must be total, 也就是在这个数据库里每个entity都必须已婚
  • partial participation: 假如现在要创建一个 某市婚姻状况 的数据库,则不需要每个entity都有对象
  • 我们可以用加粗箭头表示 total participation
  • partial participation
Keys
  • 每一个entity set, 我们会选择一个key
超码: superkey
  • 能够用来定位关系表中entity的一个或多个属性 Example: {name,S.S.N}
候选码: candidate key
  • 最小长度的超码
主键: primary key
  • DB设计者指定的candidate key用来区分不同的entity 用下划线表示
外键 foreign key
  • 一个关系表(relation)的一组字段指向另外一个关系表(relation)的一行 (有点类似pointer)
  • 通过指向另外一个关系表(relation)的primary key实现
弱实体 weak entity set
  • weak entity set: 如果一个entity set无法找出primary key, 则这个entity set是weak entity set
  • 比如下图就是weak entity set
  • 为了能找出weak entity里的数据,需要把weak entity和strong entity的primary key相连
  • 被使用的primary key叫做identifying owner
实体(entity)的继承
  • 如果A继承B, 则每个A entity也是B entity
设计ER需要考虑的因素

实体集 or 属性 (Entity set or Attribute)
  • 有时我们需要决定是否将一个property设置为一个atrribute或者设置成一个entity set
  • Example:电话号码设计成学生的属性还是设计成单独的entity set
  • 第二种设计方法的好处是可以处理一个学生可能有多个电话号码或者一个电话号码被好几个学生使用的情况
  • Example 2:如何设计学生和学生地址之间的关系
三元 or 二元 (Binary or Ternary)

三元关系例子:

三元 or 二元 ?

  • 通常如果不是确实需要三元关系,最好使用二元关系
  • 所有的三元关系以及更高元的关系都可以转变成二元关系
  • 三元关系
  • 二元关系
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/300578.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号