chapter 04 database learning skills

Upload: don-seneca

Post on 13-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/26/2019 Chapter 04 Database Learning Skills

    1/44

    Introduction to

    DatabasesChapter 4:Designing aDatabase

  • 7/26/2019 Chapter 04 Database Learning Skills

    2/44

    Designing Relational

    TablesTypical process for converting E-Rdiagrams to relational tables: Each entity converts to table

    For many-to-many relationships, each

    associative entity converts to table Attribtes become table colmns

    Ensre foreign !eys appear in proper placesin tables

    To convert single entity, create table ofsame name "ith colmn for eachattribte

  • 7/26/2019 Chapter 04 Database Learning Skills

    3/44

    Salesperson Entity and

    Table

  • 7/26/2019 Chapter 04 Database Learning Skills

    4/44

    Converting Binary

    Relationships #reater importance in selectingidenti$er and primary !ey

    %denti$er and primary !ey de$ne foreign

    !ey that establishes relationshipsbet"een tables

    &ften more than one "ay torepresent entity relationships as

    relational tables

  • 7/26/2019 Chapter 04 Database Learning Skills

    5/44

    Example: Converting ! BinaryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    6/44

    Example: Converting ! BinaryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    7/44

    Example: Converting ! Binary Relationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    8/44

    Example: Converting ! BinaryRelationship

    'onverting one-to-one(alesperson)&*ce relationship

    &ptions:

    'onvert relationship tosingle)combined table

    'onvert relationship to t"o tables

  • 7/26/2019 Chapter 04 Database Learning Skills

    9/44

    Example: Converting ! BinaryRelationship

    'onsiderations: +siness environment considers

    (alesperson and &*ce as separateentities

    odality of ero at (alesperson entity inE-R diagram .o*ce may have no oneassigned/

    (alesperson entity in E-R diagram has

    relationships "ith other entities

  • 7/26/2019 Chapter 04 Database Learning Skills

    10/44

    Example: Converting ! BinaryRelationship

    (oltion 0:

    'ombine t"o entities into one table

  • 7/26/2019 Chapter 04 Database Learning Skills

    11/44

    Example: Converting ! BinaryRelationship

    (oltion 1: T"o separate tables &*ce 2mber as foreign !ey in

    (alesperson table

  • 7/26/2019 Chapter 04 Database Learning Skills

    12/44

    Example: Converting ! BinaryRelationship

    (oltion 3:

    T"o separate tables

    (alesperson 2mber as foreign !ey in

    &*ce table

  • 7/26/2019 Chapter 04 Database Learning Skills

    13/44

    Example: Converting !" BinaryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    14/44

    Example: Converting !" BinaryRelationship

    Each occrrence of (alesperson isrelated to ero or more occrrencesof 'stomer

    4ni5e identi$er of entity on 6one7side is placed as foreign !ey in entityof 6many7 side

  • 7/26/2019 Chapter 04 Database Learning Skills

    15/44

    Example: Converting !" BinaryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    16/44

    Example: Converting "!" BinaryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    17/44

    Example: Converting "!" BinaryRelationship

    ost relational D+( systems do notdirectly spport many-to-manyrelationships

    (oltion: %nclde associative entity toestablish relationship

    ay se composite !ey as primary!ey in associative entity

  • 7/26/2019 Chapter 04 Database Learning Skills

    18/44

    Example: Converting "!" BinaryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    19/44

    Example: Converting "!" BinaryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    20/44

    Example: Converting ! #naryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    21/44

    Example: Converting ! #naryRelationship

    8ith:

    &nly one entity type involved, and

    &ne-to-one relationship

    'onversion re5ires only one table

  • 7/26/2019 Chapter 04 Database Learning Skills

    22/44

    Example: Converting !" #naryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    23/44

    Example: Converting !" #naryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    24/44

    Example: Converting "!" #naryRelationship

    any-to-many nary relationship:

    For e9ample: one prodct can beconstrcted ot of set or sbset of otherprodcts

    #eneral rle in conversion: 2mber of tables e5al to nmber of entity

    types pls one more table for many-to-manyrelationship

    - nary relationship - 1 tables - binary relationship - 3 tables

    - ternary relationship - for tables

  • 7/26/2019 Chapter 04 Database Learning Skills

    25/44

    Example: Converting "!" #naryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    26/44

    Example: Converting "!" #naryRelationship

  • 7/26/2019 Chapter 04 Database Learning Skills

    27/44

    Example: $ood ReadingBoo%stores

  • 7/26/2019 Chapter 04 Database Learning Skills

    28/44

    Example: $ood ReadingBoo%stores

  • 7/26/2019 Chapter 04 Database Learning Skills

    29/44

    Example: $ood ReadingBoo%stores

  • 7/26/2019 Chapter 04 Database Learning Skills

    30/44

    &ormali'ing Data

    Data normaliation:ethodology fororganiing attribtes into tables toeliminate redndancy among non!ey

    attribtes #oals:

    Each resltant table describes single entitytype or single many-to-many relationship

    Foreign !eys appear e9actly "here needed ;roperly strctred relational database

  • 7/26/2019 Chapter 04 Database Learning Skills

    31/44

    &ormali'ation

    Techni(ues T"o types of inpt needed for datanormaliation process

    0< =ist of all attribtes to be incorporated indatabase, inclding intersection data attribtes

    1< =ist of fnctional dependencies: all de$ningassociations bet"een attribtes

    %n fnctional dependencies, oneattribte .determinate attribte/

    de$nes vale of another attribte(alesperson 2mber > (alesperson 2ame

  • 7/26/2019 Chapter 04 Database Learning Skills

    32/44

    Salesperson Entity )ttributes

  • 7/26/2019 Chapter 04 Database Learning Skills

    33/44

    Salesperson Entity *unctional Dependencies

  • 7/26/2019 Chapter 04 Database Learning Skills

    34/44

    Example: De+ning )ttributes and *unctionalDependencies

    ?antity is de$ned by t"o combinedattribtes

    anager is de$ned independently by

    t"o attribtes Department 2mber and (alesperson

    2mber

    (alesperson 2mber also de$nes

    Department 2mber

  • 7/26/2019 Chapter 04 Database Learning Skills

    35/44

    &ormali'ing Data

    2ormal forms: Rles for data normaliation

    Three main normal forms First normal form

    (econd normal form

    Third normal form 2ormaliation:

    4ses normal forms to step throgh 6decompositionprocess7 that decomposes attribtes into sbgrops

    %n third normal form, grop of tables is

    "ell-strctred relational database "ith nodata redndancy

  • 7/26/2019 Chapter 04 Database Learning Skills

    36/44

    &ormali'ing Data

    First normal form: Eliminates mltiple vales

    (econd normal form: Eliminates partial ,unctional dependencies

    .data dependent on part of primary !ey/

    Every non!ey attribte mst be fllyfnctionally dependent on entire !ey of table

    Third normal form: Eliminates transitive dependencies .one

    non!ey attribte is fnctionally dependent onanother/

    2on!ey attribtes are not allo"ed to de$neother non!ey attribtes

  • 7/26/2019 Chapter 04 Database Learning Skills

    37/44

    Example: #nnormali'ed

    Data

  • 7/26/2019 Chapter 04 Database Learning Skills

    38/44

    *irst &ormal *orm

  • 7/26/2019 Chapter 04 Database Learning Skills

    39/44

    Second &ormal *orm

  • 7/26/2019 Chapter 04 Database Learning Skills

    40/44

    Third &ormal *orm

  • 7/26/2019 Chapter 04 Database Learning Skills

    41/44

    Denormali'ing Data

    Denormaliing may be needed "hen:

    2ormaliation has been ta!en to e9tremeToo many small tables creating more "or! and

    storage space

    E

  • 7/26/2019 Chapter 04 Database Learning Skills

    42/44

    Summary

    %n converting E-R diagrams to relationaltables, each entity typically converted intotable, "ith attribtes as table colmns