数据库原理及应用o实用教程chapter_第1页
数据库原理及应用o实用教程chapter_第2页
数据库原理及应用o实用教程chapter_第3页
数据库原理及应用o实用教程chapter_第4页
数据库原理及应用o实用教程chapter_第5页
已阅读5页,还剩16页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第二章 实体联系模型 ( ER Model)2.1 实体和实体集合2.2 联系和联系集合2.3 映射限制和关键字2.4 实体联系ER图解和将之归纳为表2.5 概括和聚集2.1 实体和实体集合1. 实体客观世界中可相互区别的事或物,specific student, company, event2. 实体集具有相同类型的实体的集合。例如一个银行里有帐户的所有人称为实体集顾客。 3. 属性、属性值分别指实体具有的特性和特性的取值。一个实体可具有多个属性,每个属性有各自的值域。student have id, names, age,sex and addresses 4. 实体集中的属性实体集中每一

2、实体都共有的属性。实体集 顾客姓名身份证号住址田举510104660811401成都市协和村刘大力510101430807101成都市花牌坊街张三510101330409201成都市花牌坊街实体集 帐户帐号金额40115200.00301300.002011300.0040232000.0063950000.00返回2.2 联系和联系集合现实世界中的事物内部或事物之间总是存在某些关联的。1. 联系实体及实体集之间存在的关联,也是实体,有自己的属性。两个实体集参与的二元联系可分为3 类:1) 一对一的联系 (1 : 1)2) 一对多或多对一的联系 (1 : n)、(n : 1)3) 多对多的联系

3、 (n : m)2. 联系集有 n 个实体集 E1,E2,En ;(e1,e2,en) 是一个联系 ;(e1,e2,en) e1E1, e2e2,enEn的子集是联系集。3.联系集中的角色一个实体集自身参与的联系,每次参与的作用。用角色名标示其含义。返回2.3 映射限制和关键字映射基集:映射基集:描述了某个实体集中的一个实体经联系集与另一个实体集中的实体相联系的实体数量。1 : 1n : 11 : mn : m关键字1. 实体集中的键码键、码在实体集能唯一相互区别实体的属性或属性组合。super key 超级键超级键:用来唯一表示实体集中的一个实体的一个或多个属性的集合。candidate k

4、ey 候选键候选键:a minimal super keycustomer(cus_num, cus_name, cus_street, cus_city), candidate key: cus_num super key: cus_num, cus_num, cus_name, cus_num, primary key(主码(主码 或或 主键)主键):one of the candidate keys selected An entity set that does not have a primary key is referred to as a weak entity set. Th

5、e existence of a weak entity set depends on the existence of a identifying entity set . In a university, a course is a strong entity and a course-offering can be modeled as a weak entityThe discriminator (or partial key) of a weak entity set is the set of attributes that distinguishes among all thos

6、e entities in a weak entity set that depend on one particular strong entiy. The discriminator of course-offering would be semester (including year) and section-number (if there is more than one section)nThe primary key of a weak entity set is formed by the primary key of the strong entity set on whi

7、ch the weak entity set is existence dependent, plus the weak entity sets discriminator.n If we model course-offering as a strong entity we would model course-number as an attribute. Then the relationship with course would be implicit in the course-number attributen In E-R model, We depict a weak ent

8、ity set by double rectangles. We underline the discriminator of a weak entity set with a dashed line.2. 联系集中的键码与一个联系集 R 相联的实体集 E1,E2,En ; 其中一个实体集主键码的属性集合 primaryKey(Ei) ;1)如果R没有自己的属性,则: primaryKey(E1) primaryKey(E2) primaryKey(En) ; 描述了R中的一个联系。2)如果R有自己的属性 a1, a2, an 则: primaryKey(E1)primaryKey(E2)pr

9、imaryKey(En) a1, a2, an 描述了R中的一个联系。3) 无论R有无自己的属性 primaryKey(E1) primaryKey(E2) primaryKey(En) 构成 R 的一个超键码。4) R 的主键码构成受映射约束的影响:* n:m 由相联的所有实体集的主键码构成。* n:1/ 1:m 由“多”方实体集的主键码构成。* 1:1 由任意一个相联的实体集的主键码构成。返回2.4 绘制ER图1. ER图的图元(图素)联系集 实体集 线段属性属性派生属性 bookstitleisbnpagetypeyearpricewriteBooknameidbirthplace2.

10、画ER图authorsbegin_date我们在实体集和联系集之间通过有向边(), 代表“1”;无向边()代表“n” contractsauthorspresses books 非二元联系集:角色的标识: authors Co_wwritemain_authorsco_authors2.6 从ER图到关系模型设计的转换bookstitleisbnpageyeartypepriceidauthorsnamebirthplacewriteBookTitleIsbnPaperTypePubdatePrice简爱7-5390568文学19917.10围棋7-8051195体育19871.40RDBMS

11、1. 实体集到关系模式的转换bookstitleisbnpageyeartypepriceidauthorsnamebirthplacewriteBookBook( title,isbn,page,type,year,price)Author(Id,Name,country,City)2. 联系集到关系模式的转换先确定联系集应具有的属性,由此决定转换后的关系应包含的属性。这些属性来自两个方面: 与联系集关联的每个实体集的键码属性/集。 联系集自有属性。bookstitleisbnpageyeartypepriceidauthorsnamebirthplacewriteBookwriteBook

12、(isbn,authorsID)begin_datewwriteBook(isbn,authorID,begin_date)3. 弱实体集到关系模式的转换pressnamepressidpostcodepressesDept unitofaddressnamenamepopulationcitiesditricts consofnamepress(pressid,pressname,address,postcode)dept(pressid,name)弱联系集unitof只为弱实体集dept找到键码。不需要为其构造关系。city(name,population)distinct(citynam

13、e,name)4. ER图中其他元素的转换bookstitleisbnyearpricepagetypeisaisacourtroomromancemainlandh_m_tforeigntranslatorregiontimeYearendingroleBook(isbn,title,page,type,year,price)CourtroomBook(isbn,ending)RomanceBook(isbn,role)ForeignRomanceBook(isbn,role,translator)H-m-tRomanceBook(isbn,role,region)MainlandRomanceBook(isbn,role,timeYear) 不需为isa联系建立关系。 5. 键码的转换(1)由单个实体集构造的关系,其键码就是该实体集的键码。关系模式中的键码从ER图中转换而来:(2)由二元联系集构造的的关系: 1)多对多联系集时,关系的键码是两个相关实体集的键码。 2)多对一联系集时,关系的键码是“多”基数实体集的键码。 3)一对一联系集时,关系的键码可以是任一个实体集的键码。bookstitleisbnpageyeartypepr

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论