Lec 5 E-R module

Lec 5 E-R model

Entity Sets

  1. Entity with several attributes is considered to be the basic block of database system.
    • Entity can be either concrete or abstract.
      • Example: specific student, company, event, plant.
    • Attribute types
      • Simple(sex : man or woman) and Composite (name : first-name, middle-name, last-name)
      • Singled-valued(id) and multi-valued(phone number)
      • Derived attributes(in another word,optional attributes, like hobbies, pets and something that's not so necessary)
  2. Entities are connected by "relationships"(will be mentioned in next part).
    • Go to next point for details

Relationship Sets

  1. relationship set is an association among several entities(usually binary)

    • Example:
    RelationSet  CustomerEntity   LoanEntity
    borrower1   Jones                  L-17
    borrower2   Mike                   L-11
        ```
    
    
  2. Binary relationship set types

    • one to one
    • one to many
    • many to one
    • many to many
  3. Keys

    • Super key : a set of some special attributes which uniquely determined each entity

    • Candidate key : minal member of super key

    • Example :
      Candidate key:{cus-num}, {cus-name},{cus-id}
      Super key:{cus-num, cus-name,cus-id}

    • The combination of primary keys participating entity sets forms a super key of relation set [e.g. (customer-id, loan-number) is the super key of borrower]

    • The difference between candidate key and primary key

      • Considering the semantics, we will select one from candidate keys to be the primary key. (?)
      • To be continued
  4. E-R Diagram

    • Basic information

      • Rectangles(长方形) represent entity sets.
      • Diamonds(菱形) represent relationship sets.
      • Lines link attributes to entity sets and entity sets to relationship sets.
      • Ellipses(椭圆) represent attributes.
        • Double ellipses represent multivalued attributes.
        • Dashed ellipses denote derived attributes.
      • Underline indicates primary key attributes

        Screen Shot 2015-05-02 at 7.24.55 PM.png
    • Sometimes there will be a descriptive attribute of the relationship such as "access-date".


      Screen Shot 2015-05-02 at 7.26.25 PM.png
    • Recursive relationship set

      Screen Shot 2015-05-02 at 7.27.10 PM.png

    • Binary relation types:

      -> : to one, -- : to many

      • Example:

        1. Customer <- borrower -> loan

          A loan is associated with at most one customer via borrower

        2. Customer <- borrower -> loan

          A customer is associated with several (including 0) loans via borrower.

        3. Customer -- borrower -> loan

          A customer is associated with at most one loan via borrower.

        4. Customer -- borrower -- loan

          A loan is associated with several (possibly 0) customers via borrower.

      • Total participation(double line) & Patial participation(single line)

      • Binary vs. Non-binary

        • Convert

          parents(he, she, child) => father(he, child), mother(she, child)

Weak Entity Sets

  1. An entity set that does not have a primary key is referred to as a weak entity set.
  2. Instead of primary key, it will have one or more discriminator or partial key.
  3. Weak entity should depend on a strong entity which has a primary key.

Extended E-R Features

  1. Specialization & Generalization

    • Similar to the "herited" concept in oop programming.
    • This should satisfy "disjoint" and "overlaping"
  2. Total and Parital

    • Total: an entity must belong to one of the lower-level entity sets.
    • Partial: an entity need not belong to one of the lower-level entity sets.
  3. Aggregation

    • Similar to the "Encapsulation" in oop programming.
    • Treat relationship as an abstract entity.


      Screen Shot 2015-05-02 at 7.44.37 PM.png

      Screen Shot 2015-05-02 at 7.44.41 PM.png

Design of an E-R Database Schema

Pass

Reduction of an E-R Schema to Tables

  1. A strong entity set => to a table with the same attributes.

  2. Composite attributes are flattened out by creating a separate attribute for each component attribute.

    • customer(customer-id,name, cust-street, cust-city)
    • name(first-name, last-name)

    ==>

    • customer(customer-id, first-name, last-name, cust-street, cust-city)
  3. A multivalued attribute M of an entity E is represented by a separate table.

    • employee(emp-id, ename, sex, age, dependent-names(Derived))

    ==>

    • employee(emp-id, ename, sex, age)
    • employee-dependent-names(emp-id, dependent-name)
  4. Many-to-one and one-to-many relationship sets that are total on the many-side can be represented by adding an extra attribute to the “many” side, containing the primary key of the one side. (If there is parital participation, there may be some NULL values which we do not care)

    • account(account-number, balance)
    • branch(branch-name, branch-city, assets)
    • account-branch(account-number,_ branch-number_)

    ==>

    • account(account-number, branch-name, balance)
    • branch(branch-name, branch-city, assets)
  5. one-to-one relationship sets, either side can be chosen to act as the “many” side.

  6. The table corresponding to a relationship set linking a weak entity set to its identifying strong entity set is redundant. (Similar to the method mention in 4.)

Representing Specialization

table table attributes
person person-id, name, street, city
customer person-id, name, street, city, credit-rating
employee person-id, name, street, city, salary
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,752评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,100评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,244评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,099评论 1 286
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,210评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,307评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,346评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,133评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,546评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,849评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,019评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,702评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,331评论 3 319
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,030评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,260评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,871评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,898评论 2 351

推荐阅读更多精彩内容