数据库mysql的ER模型、关系模式以及ER模型转化成关系模式

本文详细介绍了数据库设计中的实体关系模型(E-R模型),包括实体、关系和属性的概念,以及如何在E-R图中表示这些概念。E-R模型通过矩形表示实体,钻石表示关系,并通过连线表达不同类型的映射基数,如一对一、一对多、多对一和多对多。此外,还讨论了完全参与和部分参与的概念,以及如何用图形表示复杂约束。最后,提到了将E-R模型转换为关系模式的过程,以及关系属性的放置策略。
摘要由CSDN通过智能技术生成

Entity-Relationship Model

  1. The E-R model is a widely used data model for database design.
  2. It provides a convenient graphical representation, i.e., the E-R diagram, to view data, relationships and constraints.
  3. The E-R data model employs three basic notions:
    • Entity sets
    • Relationship sets
    • Attributes

Representing Entity sets in ER Diagram

Entity sets can be represented graphically as follows:

  • Rectangles represent entity sets
  • Attributes listed inside entity rectangle
  • Underline indicates primary key attributes

Relationship Sets

Diamonds represent relationship sets

Relationship Sets with Attributes

Mapping Cardinality

For a binary relationship set R between entity sets A and B, the mapping cardinality must be one of the following types:

  1. One to one

    An entity in A is associated with at most one (最多一个)entity in B
    An entity in B is associated with at most one entity in A

  2. One to many

    An entity in A is associated with any number (zero or more) (任意个,包括零个)of entities in B
    An entity in B is associated with at most one entity in A

  3. Many to one

    An entity in A is associated with at most one entity in B
    An entity in B is associated with any number (zero or more) of entities in A

  4. Many to many

    An entity in A is associated with any number (zero or more) of entities in B
    An entity in B is associated with any number (zero or more) of entities in A

Representing Cardinality Constraints in ER Diagram

We express cardinality constraints by drawing

  • either a directed line (->), signifying “one,”(最多一个)
  • or an undirected line (—), signifying “many,”(任意个,包括零个)

Participation

  1. Total participation (indicated by double line)

    E.g. the participation of student in advisor is total

  2. Partial participation

    E.g. the participation of instructor in advisor is partial

Notation for Expressing More Complex Constraints

  • min is the minimum of times each entity participates in relationships
  • max is the maximum of times each entity participates in relationships
  • A maximum value of * indicates no limit

Keys for Relationship Sets

If the relationship set advisor between student and instructor isthen the primary key of advisor is
many-to-many{student_id, instructor_id}
many-to-one{student_id}
one-to-many{instructor_id}
one-to-one{student_id} or {instructor_id}

Weak Entity Set

does not have sufficient attributes to form a primary key

Strong Entity Set

has a primary key

Identifying relationship
  • A weak entity set must relate to a identifying entity set 标识实体集( owner entity set ) via an identifying relationship
  • one-to-many from the identifying to the weak entity set
  • the participation of the weak entity set is total

Reducing E-R Diagrams to Relational Schemas

Reduction to Relational Schemas

  1. Requirement Analysis

  2. Conceptual Design

    Translate user requirements to a Entity-Relationship model

  3. Logical Design

    The designer maps the Entity-Relationship model into a relational database schema

  4. Physical Design

Representing Relationship Sets

  • many-to-many
  • many-to-one
  • one-to-one

relationship sets to relation schemas

  1. many-to-many

    a schema with attributes for the primary keys of the two participating entity sets, and any descriptive attributes of the relationship set.

    advisor = (s_id, i_id)

  2. many-to-one

    adding the primary key of the “one” side to the “many” side

    instructor = ( ID, name, salary, dept_name)

  3. one-to-one

    **For one-to-one relationship sets, extra attribute can be added to either side **

    instructor = ( ID, name, salary, student_id )
    student = ( ID, name, tot_cred )
    OR
    instructor = ( ID, name, salary )
    student = ( ID, name, tot_cred, instructor_id )

Placement of Relationship Attributes

  • Attributes of a one-to-many relationship set can be repositioned to the entity set on the many side
  • Attributes of a one-to-one relationship set can be repositioned to either side

Exercises:

Entity author: author = ( name, address, URL )
Entity book: book = ( ISBN, title, year, price )
Relationship written-by:
book = ( ISBN, title, year, price, author_name )

Result:
author = ( name, address, URL )
book = ( ISBN, title, year, price, author_name )

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值