Entity-Relational Data Modeling

本文介绍了实体关系模型(ERM),一种用于创建系统概念架构的数据库方法。详细解释了实体、属性和关系的概念,并提供了如何将ERM转换为关系模式的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Introduction
An Entity-Relational Model(ERM) is an abstract and conceptual representation of data. It is a DB method used to produce a type of conceptual schema of a system.

ER Definitions
Entity(Instance)
An entity is an instance of a physical object in the world.
Attributes:
Properties of entities that describe their characteristics.
Types:
simple
Composite:
Multiple.
Relationships:
1. Relationship are bi-directional, they can be phrased both ways.
2. Degree:
• binary involving two entities.
• ternary involving three entities.
3. Cardinality: Defines how many entities are involved in a
relationship.
4. Relationships may have properties (attributes).
5. Relationships can be recursive.

Translating ER Models to Relational Schema
Use ER Models to convert into schema.

Strong Entities
Each strong entity becomes a relation.

Week Entities
Convert each weak entity into a relation with a foreign key to
its identifying entity.
• Identify the owning entities E1, E2, … , En.
• Create a relation R for the weak entity.
• The primary key of R is the primary keys of the owning entities
plus the partial key of the weak entity.
• Create foreign keys in R for the primary keys in the owning entities.
• Attributes are converted in a similar manner as strong entities.

1:1 Relationship
Convert a 1:1 relationship, R, between entities Ei and Ej into unique foreign keys references from the relations representing both entities.
• Identify the relations Ri and Rj that correspond to the entities Ei and Ej.
• Choose one of the relations, say Ri.
• Choose the entity/relation that will always participate in the relationship.
• Add the attributes of R to Ri.
• Add the primary key attributes of Rj to Ri and create a foreign key reference.
• Make sure the primary key attributes of Rj are unique

1:N Relationships
Convert a 1:N relationship (or N:1 relationship), R, between entities Ei and Ej into a foreign key references from the N-sided entity to the 1-sided entity.
• Identify the relations Ri and Rj that correspond to the entities Ei and Ej.
• Choose the N-sided relation, say Ri.
• Add the attributes of R to Ri.
• Add the primary key attributes of Rj to Ri and create a foreign key reference to Rj from Ri.

M :N Relationships
Convert a M:N relationship, R, between entities Ei and Ej into a new relation R with foreign key references to the two participating entities.
• Identify the relations Ri and Rj that correspond to the entities Ei and Ej.
• Create a new relation R.
• Add the attributes of the relationship to R.
• The primary key of R is a composite of the primary keys of Ri and Rj and create a foreign key reference from R to Rj and to Ri.

Multi-valued Attributes
Convert multi-values attributes into a relation with a composite key of the attribute value and the primary key of the attribute’s entity.
• Identify the entity’s relation, Ri.
• Create a relation R for the multi-value attribute where R contains:
• a single-value attribute; and
• Ri’s primary key, which is a foreign key from R to Ri .
• The primary key of R is a composite key of the attribute value and Ri’s primary key

### 数据建模的概念 数据建模是在信息系统开发过程中定义、分析和表示数据需求的过程。通过创建模型来描述系统的结构及其行为,从而帮助理解复杂的数据关系并支持决策制定。数据建模不仅限于数据库设计;它还涵盖了业务流程优化、数据分析等多个方面。 #### 主要概念 - **实体(Entity)**:代表现实世界中的对象或事件,在计算机系统内作为独立存在的事物被识别。 - **属性(Attribute)**:用于描述实体特征的信息项。 - **关系(Relationship)**:两个或多个人之间存在关联的方式,可以是一对一(one-to-one),一对多(one-to-many)或多对多(many-to-many)[^1]。 ### 常见的数据建模技术 #### 关系型数据建模 这是最常用的一种方式,基于表格形式存储信息,并利用键(key)建立不同表之间的联系。SQL(Structured Query Language)是操作这类数据库的标准语言之一。 #### 面向对象数据建模 这种方法试图更贴近实际世界的思维方式去构建软件应用,其中类(class)用来封装数据与其上的操作方法。面向对象编程(Object-Oriented Programming,OOP)就是以此为基础发展起来的技术体系[^2]。 #### NoSQL数据建模 随着大数据时代的到来,NoSQL(non-relational database management system)逐渐兴起。NoSQL不依赖固定的模式(schema-less),能够灵活处理各种类型的海量异构数据集,如文档(Document-oriented databases)、列族(Column-family stores)等。 ### 工具介绍 对于上述提到的不同种类的数据建模活动,市场上有许多优秀的工具可供选择: - **ER/Studio** 和 **MySQL Workbench**: 这两款都是强大的可视化编辑器,特别适合进行关系型数据库的设计工作; - **MongoDB Compass**, **ArangoDB Studio**: 提供直观界面让用户轻松管理非关系型数据库资源,非常适合那些正在探索NoSQL解决方案的人群; - **StarUML**, **Visual Paradigm**: 支持多种图形化表达手段(比如UML图),有助于提高团队协作效率以及促进跨部门沟通交流。 ```sql CREATE TABLE Employees ( ID INT PRIMARY KEY, Name VARCHAR(50), Position VARCHAR(30), Salary DECIMAL(10, 2) ); ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值