在本章中,您将学习: Map an ER diagram to a table 将 ER 图映射到表

20
幻幻幻 1 16 幻幻2幻 Ver. 1.0 幻幻幻幻幻幻幻幻在在在在 在在在在在 ,: Map an ER diagram to a table 在 ER 在在在在在 幻幻

description

在本章中,您将学习: Map an ER diagram to a table 将 ER 图映射到表. 目标. Reflects entities and their relationships, based on the data processing needs of an organization 概念模型根据公司的数据处理需求,反映实体及其关系。 - PowerPoint PPT Presentation

Transcript of 在本章中,您将学习: Map an ER diagram to a table 将 ER 图映射到表

Page 1: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 1(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

在本章中,您将学习:Map an ER diagram to a table 将 ER 图映射到表

目标

Page 2: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 2(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

Reflects entities and their relationships, based on the data processing needs of an organization 概念模型根据公司的数据处理需求,反映实体及其关系。The conceptual model design is not concerned with the implementation and operation phases of database. The conceptual model can be mapped to a relational, hierarchical, or network model 概念模型的设计并不考虑数据库的实现及操作阶段,概念模型可以映射到关系、分层或网络模型。Is independent of individual applications, database management systems, hardware, and physical storage of data. 它独立于应用程序、数据库管理系统、硬件和数据的物理存储。 Data analysis is the first step in designing a conceptual model. 设计概念模型第一步数据分析 .( 收集数据—整理消除重复数据—识别实体、属性、关系 )

Draw ER diagram 画 ER 图。

Conceptual Model 概念模型

Page 3: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 3(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

A database that conforms to an ER diagram can be represented by a collection of tables in the relational system. 在关系系统中,符合 ER 图的数据库可以由表的集合来表示。The mapping of ER diagrams to tables can be discussed in relation to the following 让我们来讨论 ER 图到表的映射:

Regular entities 常规实体Attributes 属性Relationships 关系Weak entities 弱实体Subtypes and Supertypes 子类型和超类型

Mapping ERDs to Tables 将 ER 图映射到表

Page 4: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 4(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

They can exist in isolation, independent of any other entity. 它们可以孤立地存在,与任何其他实体无关。They are the “building blocks” of the database 它们是数据库的“构建块”。Each regular entity maps to a table. 每个常规实体映射到表。

Regular Entities 常规实体

STUDENT BOOKSISSUES

Page 5: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 5(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

Each property or attribute shown in the ER diagram maps to a column in the appropriate table. ER 图中显示的每个特性或属性映射到相应表中的列。 [P2.4]

The primary key in the table is identified as the key in the ER diagram. 在 ER 图中标识的键属性映射到表中做为主键。

Attributes 属性

ADDRESSNAME

ROLL_NO STUDENT BOOKS

CODE DESC

PRICEISSUES

ROLL_NO NAME ADDRESS CODE PRICE DESC

Page 6: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 6(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

Each type of relationship maps to tables in a different manner in the relational database management system. 在关系数据库管理系统中,每种关系以不同的方式映射到表。The most important principle is to create tables where information from the real world is stored and retrieved in an optimal way; that is, a minimum number of tables with a minimum number of attributes. 最重要的一个原则是要创建一些表,通过这些表,使现实世界中的信息能够以最佳的方式存储和获取,即,创建最少数量的表,每个表具有最少的属性数。In a relational system, a join operation retrieves all information by combining two or more tables. 在关系系统中,连接操作通过将两个或多个表组合起来以获取所有信息。有以下类型:

One-to-One 一对一One-to-Many 一对多Many-to-Many 多对多

Relationships 关系

Page 7: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 7(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

In one-to-one relationships, one instance of an entity can relate to only one instance of the related entity. 在一对一关系中,一个实体的实例只与相关实体的一个实例相关联。有两种常见的映射方法:

One way to handle it is y storing a foreign key in either table 创建两个表,在任意一个表中添加一个外键和关系的属性。Another way is to merge the two tables into one for faster access. 将两个实体合并为一个表

一对一关系 One –to – One

ROLL_NO NAME ADDRESS PRJ_NAME DUATION

STUDENT PROJECTDoes1 1

Page 8: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 8(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

In one-to-many relationship, one instance of an entity can relate to more than one instance of the related entity. 在一对多关系中,一个实体的实例可以与相关实体的多个实例相关联。映射方法:

映射为两个表,在多的那端的表中添加一个外键列

一对多关系 One –to – Many

DEPARTMENT EMPLOYEEHAS1 m

DEPT_ID DEPT_NAME ...

D001 Marking

D002 Accounts

EMP_ID NAME DEPT_ID ...

E001 Robert D001

E002 Polly D002

E003 David D001

Page 9: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 9(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

映射方法:将实体映射为表,将关系也映射为一个表,并在关系表中添加两个外键列,分别映射到两个实体表的主键关系表的主键可以是复合主键也可以新增一个主键

多对多关系 Many –to – Many

STUDENT BOOKSISSUESm m

ROLL_ID NAME ...

S001 Zhangsan

S002 Lisi

CODE DESC ...

B001 C#

B002 JAVA

ROLL_ID CODE ISSUE_DT ...

S001 B001 ...

S001 B002

S002 B001

Page 10: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 10(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

A weak entity is an entity whose existence depends on some other entity. 弱实体是这样一种实体,它的存在要依赖于其他实体。It cannot exist if the entity on which it depends does not exist. 如果它所依赖的实体不存在,那么它也不能存在。将弱实体映射为一张表 , 并在表中增加一列外键对所依赖的实体的引用。

Weak Entities 弱实体

Page 11: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 11(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

Each entity type (subtypes and supertypes) maps to a separate table. 每个实体类型(子类型或超类型)映射到不同的表。The primary key of the supertype is the foreign key of the subtype 超类型的主键是子类型的外键:

它创建两者之间的链接。子类型的外键也是其主键。

子类型和超类型

CODE CONTENT

NAMECOURSE

STANDALONE SEMESTER

DUARATION SEMESTER_NO

COURSE(CODE , NAME , CONTENT)STANDALONE(CODE , DUATION)SEMESTER(CODE , SEMESTER_NO)

Page 12: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 12(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

Attributes 属性:Do not introduce any unnecessary attributes 不要引入任何不需要的属性。An attribute serves three purposes 属性有三个作用:

To identify its owner entity 标识其所有者实体To refer to another entity 引用另一个实体To simplify the description of an entity 简化实体描述

如果有具有相同属性的多个实体,则要合并。【 P2.13 】Keys 键:

Relational systems require keys that uniquely identify the rows of a table. 关系系统需要能够唯一标识表行的键。有各种类型的键:

Primary Key 主键Foreign Key 外键Candidate 候选键Alternate 替换键Composite 组合键

Tips on Logical Database Design 逻辑数据库设计技巧

Page 13: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 13(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

Any attribute (or set of attributes) that uniquely identifies a row in a table is a candidate for the primary key , such an attribute is called a candidate key. 能够唯一标识表中行的属性(或属性集)是主键的一个候选键。 这样的属性称为 候选键。Any attribute that is a candidate for the primary key but is not the primary key is called the alternate key. 任何一个作为主键的候选键、但它又不是主键的属性,这样的属性称为替换键。Keys can be simple or composite 键可以是简单的或组合的键:

A simple key is composed of a single attribute. 简单键由单个属性组成。A composite key, on the other hand, comprises two or more attributes. 组合键则是由多个属性组合起来。 [P2.15]

逻辑数据库设计技巧(续)

ENGINE# REGN# DESCRIPTION

135268 2362 Honda

833647 7389 Mercedes

784799 8399 BMW

347889 9077 Rolls Royce

Page 14: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 14(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统课间思考

定义以下术语:1. Candidate Key 候选键2. Alternate Key 替换键

答案:1. 能够唯一标识表行的任何属性(或属性集)是主键的一个候选。这样的属性称为候选键。

2. 任何是主键的候选但不是主键的属性,这样的属性称为替换键。

Page 15: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 15(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统逻辑数据库设计技巧(续)

Entities 实体:Some attributes may acquire further attributes during database design and become entities. 数据库设计期间某些属性可以获得进一步的属性来限制自己,并且成为实体。

EMPLOYEE

ADDRESS EMPNOCITY

EMPLOYEE SITUATED ADDRESS

STATE

BLOCK STREET

Page 16: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 16(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统逻辑数据库设计技巧(续)

Subentities 子实体:Replace optional attributes of an entity with subentities. This is called specialization. 用子实体来替换可选属性。这被称为规范化。Specialization is the result of taking a subset of a higher-level entity set to form a lower-level entity set. 规范化是采用高级实体集的子集来形成低级实体集的结果。【 P2.17 】Generalization is the result of taking the union of two or more lower-level entity sets to produce a higher‑level entity set. 一般化是采用两个或多个低级实体集来产生高级实体集的结果。【 P2.18 】

Page 17: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 17(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

问题描述将 ER 图映射到相应的表。【 P2.19 】

演示:将 ER 图映射到表

Page 18: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 18(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

在本章中,您学习了:The conceptual model reflects entities and their relationships. Data analysis helps determine entities and relationships. The conceptual model is independent of the system where it is to be implemented. 概念模型反映实体及其实体之间的关系。数据分析帮助您确定实体和关系。概念性模型独立于实施它的系统。Regular entities are not dependent. They can exist in isolation, independent of any other entity. 常规实体是独立的。它们可以独立存在,不依赖于其他实体。Each entity maps to a table. Each attribute in an E/R diagram maps to an attribute in a table. 每个实体映射到表。 ER 图中的每个属性映射到表中的列。Entities with common attributes should be merged. Attributes may acquire further attributes and become entities. 具有公共属性的实体应该合并起来,属性可以获得进一步获得属性,并且成为实体。The mapping of relationships depends on the type of relationship. Each type of relationship maps to tables in a different manner in the relational database management system. 关系映射取决于关系类型。每种关系以不同的方式映射到关系数据库管理系统中的表。

小结

Page 19: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 19(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

In one-to-one relationships, one instance of an entity can relate to only one instance of the related entity. 在一对一关系中,实体的一个实例可以只与相关实体的一个实例相关联。In a one-to-many relationship, one instance of an entity can relate to more than one instance of the related entity. 在一对多关系中,实体的一个实例可以与相关实体的多个实例相关联。Many-to-many relationships map to tables. One-to-one relationships are not very common and may map to foreign keys in tables. 多对多关系映射到表。一对一关系不是十分常用的关系,并且可以映射到表中的外键。A weak entity is an entity whose existence depends on some other entity. 弱实体是其存在需要依赖于其他实体的实体。A subtype is a subset of another entity. A subtype is always dependent on supertype for its existence. 子类型是另一个实体的子集。子类型的存在总是依赖于其他的超类型。The primary key of the supertype is the foreign key of the subtype. It creates a link between the two. 超类型的主键是子类型的外键。它创建两者之间的链接。

小结(续)

Page 20: 在本章中,您将学习: Map an ER diagram to a table     将  ER  图映射到表

幻灯片 20(共 16张)

第 2 章Ver. 1.0

关系数据库管理系统

A candidate key is a candidate for the primary key. An alternate key is a candidate key that is not a primary key. 候选键是主键的一个候选,替代键是一个不是主键的候选键。Optional attributes should be replaced with subentities; this is also called specialization. 可选属性应该由子实体代替。它也称为规范化。To simplify multiple references, a new superentity should be introduced; this is also called generalization. 要简化多个引用,应该引入一个新的超级实体,这也称为一般化。

小结(续)