SlideShare uma empresa Scribd logo
1 de 81
Gegevensbanken
entiteit-relatie model
       Prof. Erik Duval
         2009 - 2010




              1
http://www.slideshare.net/erik.duval




2
3
•   ontwerp van een gegevensbank
•   conceptuele gegevensmodellen
•   voorbeeld
•   E-R model
•   E-R diagrammen
•   ontwerpkeuzes
•   niet-binaire relaties


                            4
ontwerp van een
gegevensbank
6
•   analyse
    •   welke behoeften? welk gegevens zijn hiervoor nodig?




                               6
•   analyse
    •   welke behoeften? welk gegevens zijn hiervoor nodig?
•   conceptueel ontwerp
    •   beschrijving van gegevenstypes, relaties, restricties
        en operaties
    •   volgens hoog-niveau gegevensmodel




                                  6
•   analyse
    •   welke behoeften? welk gegevens zijn hiervoor nodig?
•   conceptueel ontwerp
    •   beschrijving van gegevenstypes, relaties, restricties
        en operaties
    •   volgens hoog-niveau gegevensmodel
•   transformatie naar implementatiemodel
    •   conceptueel schema volgens model van DBMS



                                  6
•   analyse
    •   welke behoeften? welk gegevens zijn hiervoor nodig?
•   conceptueel ontwerp
    •   beschrijving van gegevenstypes, relaties, restricties
        en operaties
    •   volgens hoog-niveau gegevensmodel
•   transformatie naar implementatiemodel
    •   conceptueel schema volgens model van DBMS
•   fysisch ontwerp
    •   intern schema volgens model van DBMS
                                  6
7
conceptueel
gegevensmodel
9
•   bedoeling:
    •   relevant deel van de werkelijkheid beschrijven
        •   objecten + feiten




                                9
•   bedoeling:
    •   relevant deel van de werkelijkheid beschrijven
        •   objecten + feiten
•   beschrijving = schema
    •   elke groep gebruikers heeft eigen schema
    •   alle schema's samen: infologisch schema




                                9
•   bedoeling:
    •   relevant deel van de werkelijkheid beschrijven
        •   objecten + feiten
•   beschrijving = schema
    •   elke groep gebruikers heeft eigen schema
    •   alle schema's samen: infologisch schema
•   modellering gebruikt abstractie
    •   details weggelaten
    •   algemene, gemeenschappelijke eigenschappen en feiten
                                9
10
•   waarom
    •   sluit nauwer aan bij realiteit dan een implementatiemodel
    •   bevat meer informatie omtrent betekenis van objecten
        dan implementatiemodellen
    •   ... en minder informatie omtrent details van implementatie




                                10
•   waarom
    •   sluit nauwer aan bij realiteit dan een implementatiemodel
    •   bevat meer informatie omtrent betekenis van objecten
        dan implementatiemodellen
    •   ... en minder informatie omtrent details van implementatie
•   gebruikte model: entiteit-relatie-model
    •   objecten
    •   verbanden tussen objecten (relaties)
    •   eigenschappen (attributen)
    •   waardenverzamelingen (domeinen)
                                10
11
•   entiteiten 

   ∈ entiteitstype




                         11
•   entiteiten 

   ∈ entiteitstype

•   relaties 
 
    ∈ relatietype




                         11
•   entiteiten 

       ∈ entiteitstype

•   relaties 
 
        ∈ relatietype

•   attributen: waarden 
 ∈ domein




                             11
•   entiteiten 

       ∈ entiteitstype

•   relaties 
 
        ∈ relatietype

•   attributen: waarden 
 ∈ domein




                             11
•   entiteiten 

           ∈ entiteitstype

•   relaties 
 
            ∈ relatietype

•   attributen: waarden 
 ∈ domein


•   sleutel
    •   identificator v.e. entiteitstype / relatietype
    •   waarde van sleutel bepaalt eenduidig de entiteit / relatie


                                  11
voorbeeld:
bedrijf
•   ...
•   bedrijf is georganiseerd in departementen

•   een departement heeft naam, nummer, een of meer locaties,
    departementshoofd (sinds een bepaalde datum)

•   elk departement controleert een aantal projecten
    elk project heeft naam, nummer, 1 locatie

•   voor elke werknemer

    •   naam, ID, adres, salaris, geslacht, geboortedatum, #uren per week
        besteed aan elk project, onmiddellijke overste (supervisor)

•   een werknemer hoort bij 1 departement,
    maar kan aan meerdere projecten werken die niet noodzakelijk
    door 1 departement gecontroleerd worden

•   voor elke werknemer bovendien van de personen ten laste

    •   naam, geslacht, geboortedatum, relatie tot werknemer
•   schema: mini-wereld

•   entiteit: object (fysisch of conceptueel)

    •   entiteit type: klasse

•   attribuut: eigenschap

    •   samengesteld / enkelvoudig (atomair)

    •   eenwaardig / meerwaardig

    •   expliciet voorgesteld / afgeleid

    •   domein (= mogelijke waarden)

    •   null-waarden:

        •   "heeft geen waarde" : niet van toepassing / onbekend

    •   nesten van samengestelde / meerwaardige attributen
sleutel

•   attribuut waarvan de waarden verschillen voor elke
    verschillende entiteit, in elke mogelijke instantie
•   soms combinatie van attributen
•   soms meer dan één sleutel




                                20
ontwerp van ER schema

identificeer
 •   entiteitstypes
 •   attributen van elk entiteitstype
 •   sleutelattributen



                              21
22
Fname    Minit     Lname
                           Salary
        Name
 Sex             Address

Ssn      EMPLOYEE


Bdate




                                    22
Fname    Minit     Lname                        Number
                           Salary        Name
        Name                                          Locations
 Sex             Address

Ssn      EMPLOYEE                        DEPARTMENT


Bdate




                                    22
Fname    Minit     Lname                               Number
                           Salary               Name
        Name                                                 Locations
 Sex             Address

Ssn      EMPLOYEE                               DEPARTMENT


Bdate




                                                 PROJECT



                                         Name                   Location

                                                    Number




                                    22
Fname    Minit     Lname                                                         Number
                           Salary                                         Name
        Name                                                                           Locations
 Sex             Address

Ssn      EMPLOYEE                                                         DEPARTMENT


Bdate




                                                                           PROJECT



                                                                   Name                   Location
                                      DEPENDENT

                                                                              Number
                      Name
                                                    Relationship
                                Sex     Birthdate

                                          22
relatie

•   relatietype = verzameling verbanden (relaties)
                  over entiteitstypes E1, ..., En
•   graad = aantal betrokken entiteitstypes
    •   binair, ternair, ...
•   1 entiteitstype meerdere keren: recursief relatietype
    •   vb. SUPERVISION
•   entiteitstype speelt rol in een relatie

                                  23
24
25
26
ontwerp van ER schema
identificeer
 •   entiteitstypes en attributen van elk entiteitstype
     •   sleutelattributen
 •   relatietypes en attributen van elk relatietype
     •   connectiviteit en deelnamebeperkingen
 •   eventuele afgeleide attributen in entiteitstypes
     •   vb: aantal werknemers in een departement
                              27
28
Fname    Minit     Lname
                           Salary
        Name
 Sex             Address

Ssn      EMPLOYEE


Bdate




                                    28
Fname    Minit     Lname                        Number
                           Salary        Name
        Name                                          Locations
 Sex             Address

Ssn      EMPLOYEE                        DEPARTMENT


Bdate




                                    28
Fname    Minit     Lname                               Number
                           Salary               Name
        Name                                                 Locations
 Sex             Address

Ssn      EMPLOYEE                               DEPARTMENT


Bdate




                                                 PROJECT



                                         Name                   Location

                                                    Number




                                    28
Fname    Minit     Lname                                                         Number
                           Salary                                         Name
        Name                                                                           Locations
 Sex             Address

Ssn      EMPLOYEE                                                         DEPARTMENT


Bdate




                                                                           PROJECT



                                                                   Name                   Location
                                      DEPENDENT

                                                                              Number
                      Name
                                                    Relationship
                                Sex     BirthDate

                                          28
Fname    Minit     Lname                                                         Number
                           Salary                                         Name
        Name                             WORKS_FOR                                     Locations
 Sex             Address

Ssn      EMPLOYEE                                                         DEPARTMENT


Bdate




                                                                           PROJECT



                                                                   Name                   Location
                                      DEPENDENT

                                                                              Number
                      Name
                                                    Relationship
                                Sex     BirthDate

                                          28
Fname    Minit     Lname                                                           Number
                           Salary                                           Name
        Name                             WORKS_FOR                                       Locations
 Sex             Address

Ssn                                            StartDate
         EMPLOYEE                                                           DEPARTMENT


Bdate
                                           MANAGES




                                                                             PROJECT



                                                                     Name                   Location
                                      DEPENDENT

                                                                                Number
                      Name
                                                      Relationship
                                Sex     BirthDate

                                          28
Fname    Minit     Lname                                                           Number
                           Salary                                           Name
        Name                             WORKS_FOR                                       Locations
 Sex             Address

Ssn                                            StartDate
         EMPLOYEE                                                           DEPARTMENT


Bdate
                                           MANAGES
                                                                             CONTROLS




                                                                             PROJECT



                                                                     Name                   Location
                                      DEPENDENT

                                                                                Number
                      Name
                                                      Relationship
                                Sex     BirthDate

                                          28
Fname    Minit     Lname                                                           Number
                           Salary                                           Name
        Name                             WORKS_FOR                                       Locations
 Sex             Address

Ssn                                            StartDate
         EMPLOYEE                                                           DEPARTMENT


Bdate
                                           MANAGES
                                                                             CONTROLS



        SUPERVISES
                                                                             PROJECT



                                                                     Name                   Location
                                      DEPENDENT

                                                                                Number
                      Name
                                                      Relationship
                                Sex     BirthDate

                                          28
Fname    Minit     Lname                                                           Number
                           Salary                                           Name
        Name                             WORKS_FOR                                       Locations
 Sex             Address

Ssn                                            StartDate
         EMPLOYEE                                                           DEPARTMENT


Bdate
                                           MANAGES
                                                                             CONTROLS



        SUPERVISES
                                       HAS_DEP.
                                                                             PROJECT



                                                                     Name                   Location
                                      DEPENDENT

                                                                                Number
                      Name
                                                      Relationship
                                Sex     BirthDate

                                          28
Fname    Minit     Lname                                                           Number
                           Salary                                           Name
        Name                             WORKS_FOR                                       Locations
 Sex             Address

Ssn                                            StartDate
         EMPLOYEE                                                           DEPARTMENT


Bdate
                                           MANAGES
                                                            Hours            CONTROLS


                                                    WORKS_ON
        SUPERVISES
                                       HAS_DEP.
                                                                             PROJECT



                                                                     Name                   Location
                                      DEPENDENT

                                                                                Number
                      Name
                                                      Relationship
                                Sex     BirthDate

                                          28
beperkingen op relatietypes
•   connectiviteit ("cardinality ratio")
     •   voor binaire relatietypes: 1:1, 1:n, m:n
         •   vb. werknemer behoort bij precies één departement
     •   ternaire, ... relatietypes: meer mogelijkheden
•   deelnamebeperking
     •   totale / partiële deelname
         •   vb. moet iedereen bij een departement behoren?
     •   voor binaire relatietypes: T-T, T-P, P-P
     •   totale deelname = "bestaansafhankelijkheid"
                                29
1:n en totaal voor employee en department
                   30
1:n en partieel voor supervisor en supervisee rol
                       31
1:1, totaal voor department en partieel voor employee

                         32
attributen van relatietypes

•   vb. aantal uren / week dat werknemer aan project werkt
•   1 : 1 ➡ attribuut kan bij een van de entiteitstypes
•   1 : n ➡ attribuut kan bij entiteitstype aan n-zijde
•   m : n ➡ attribuut kan niet bij entiteitstypes
     •   moet bij relatietype zelf
     •   vb: WORKS_ON: Hours


                                     33
Fname         Minit     Lname                                                                      Number
                                    Salary                                                  Name
             Name                              N      WORKS_FOR             1                            Locations
 Sex                  Address

Ssn                                                            StartDate
              EMPLOYEE                                                                      DEPARTMENT

                                                                           1
Bdate                                          1                                                   1
                                                           MANAGES
                                                                               Hours         CONTROLS
supervisor                  supervisee
                                                      1
                                                                N
        1                       N                                                                  N
             SUPERVISES                                              WORKS_ON          M
                                                    HAS_DEP.
                                                                                             PROJECT

                                                           N
                                                                                     Name                   Location
                                                   DEPENDENT

                                                                                                Number
                           Name
                                                                      Relationship
                                         Sex         BirthDate

                                                          34
zwakke entiteitstypes
•   zonder eigen sleutel
•   identificatie via entiteit van ander entiteitstype
•   identificerende entiteit = "eigenaar", identificerende relatie
•   steeds totale deelname in identificerende relatie
•   partiële sleutel
     •   identificeert entiteit binnen entiteiten met zelfde eigenaar
     •   partiële sleutel = "discriminator"
•   vb : DEPENDENT
                                   35
•   bestaansafhankelijkheid
    •   bestaan ene hangt af van bestaan van andere
    •   ondergeschikte entiteit - dominante entiteit
•   identificatieafhankelijkheid
    •   kan niet geïdentificeerd worden met eigen attributen
    •   = zwakke entiteit

    •   vb. straat ← gemeente ← land
•   vaak samen, maar niet altijd

                                  36
– ENTITEIT :
   • enkelvoud (bv. PERSOON, niet PERSONEN)
– RELATIE :
   • vervoegd werkwoord
– Attribuut
– Sleutelattribuut
– rolnaam




                             37
38
39
alternatieve notatie

(min,max) annotatie bij rol

hoe vaak kan een entiteit die rol spelen in een relatie?
                   min = 0 → partieel
                   min > 0 → totaal




                               40
Fname          Minit     Lname                                                                      Number
                                   Salary                                                    Name
              Name                                      WORKS_FOR             (4,N)                          Locations
 Sex                   Address
                                            (1,1)

Ssn                                                            StartDate
               EMPLOYEE                                                                      DEPARTMENT
                                       (0,1)
                                                                           (1,1)                     (0,N)
Bdate
                                                          MANAGES
                             (0,1)                                           hours            CONTROLS
      (0,N)
                                 supervisee                (1,N)
supervisor
                                               (0,N)                                                 (1,1)
                                                                      WORKS_ON (1,N)
              SUPERVISES
                                                     HAS_DEP.
                                                                                              PROJECT

                                                              (1,1)
                                                                                      Name                   Location
                                                    DEPENDENT

                                                                                                 Number
                            Name
                                                                       Relationship
                                        Sex            BirthDate

                                                         41
ontwerpkeuzes
• attribuut verwijst naar ander entiteitstype ➡ relatie
  • vb. manager als attribuut bij DEPARTMENT
      of als relatie ts. DEPARTMENT en EMPLOYEE
•   attribuut bij verschillende entiteitstypes ➡ entiteitstype
    • vb. STUDENT, INSTRUCTOR en COURSE een
      attribuut ‘Departement’ ➡ entiteit DEPARTMENT
•   entiteitstype met één attribuut met één entiteitstype
    relatie ➡ attribuut
    • vb. entiteitstype DEPARTMENT met slechts één
      attribuut, en enkel relatie met STUDENT ➡attribuut


                                  42
UML klasse diagram




        43
niet-binaire relaties

•   vb. van ternaire relatie: SUPPLY
    •   leverancier levert onderdelen voor project
    •   SUPPLIER, PART en PROJECT in relatie SUPPLY
•   connectiviteit en deelnamebeperking
    •   ingewikkelder, met (min, max) notatie
•   is ternaire relatie ook via binaire relaties voor te stellen?

                                44
45
Quantity
SuppNo                                                  ProjNo


           (0,N)                       (1,N)
SUPPLIER           SUPPLIES_FOR                     PROJECT


                            (0,N)

                                               PartNo
                      PART




                       46
een ternair relatietype vervangen door drie binaire relatietypes?




    SuppNo                                                              ProjNo

                                                Quantity

    SUPPLIER            (0,N)                               (1,N)   PROJECT

                                     SUPPLIES_FOR


                                               (0,N)


                                           PART




                                           PartNo



                                          47
een ternair relatietype vervangen door drie binaire relatietypes?




    SuppNo                                                              ProjNo

                                                Quantity

    SUPPLIER            (0,N)                               (1,N)   PROJECT

                                     SUPPLIES_FOR


                                               (0,N)


   CAN_SUPPLY                              PART




                                           PartNo



                                          47
een ternair relatietype vervangen door drie binaire relatietypes?




    SuppNo                                                              ProjNo

                                                Quantity

    SUPPLIER            (0,N)                               (1,N)   PROJECT

                                     SUPPLIES_FOR


                                               (0,N)


   CAN_SUPPLY                              PART                      USES




                                           PartNo



                                          47
een ternair relatietype vervangen door drie binaire relatietypes?




                                      PARTICIPATES

    SuppNo                                                              ProjNo

                                                Quantity

    SUPPLIER            (0,N)                               (1,N)   PROJECT

                                     SUPPLIES_FOR


                                               (0,N)


   CAN_SUPPLY                              PART                      USES




                                           PartNo



                                          47
48
49
Vragen...?

    50

Mais conteúdo relacionado

Mais de Erik Duval

eCloud newspapers
eCloud newspaperseCloud newspapers
eCloud newspapersErik Duval
 
InfoVis1415: slides sessie 12, 18 mei 2015
InfoVis1415: slides sessie 12, 18 mei 2015InfoVis1415: slides sessie 12, 18 mei 2015
InfoVis1415: slides sessie 12, 18 mei 2015Erik Duval
 
InfoVis1415: slides sessie 11, 11 mei 2015
InfoVis1415: slides sessie 11, 11 mei 2015InfoVis1415: slides sessie 11, 11 mei 2015
InfoVis1415: slides sessie 11, 11 mei 2015Erik Duval
 
InfoVis1415: slides sessie 10, 4 mei 2015
InfoVis1415: slides sessie 10, 4 mei 2015InfoVis1415: slides sessie 10, 4 mei 2015
InfoVis1415: slides sessie 10, 4 mei 2015Erik Duval
 
Evaluation
 of information visualisation
Evaluation
 of information visualisationEvaluation
 of information visualisation
Evaluation
 of information visualisationErik Duval
 
InfoVis1415: slides sessie 9, 27 april 2015
InfoVis1415: slides sessie 9, 27 april 2015InfoVis1415: slides sessie 9, 27 april 2015
InfoVis1415: slides sessie 9, 27 april 2015Erik Duval
 
Social Media and Science a wedding made in Heaven...
 or in Hell?
Social Media and Science a wedding made in Heaven...
 or in Hell?Social Media and Science a wedding made in Heaven...
 or in Hell?
Social Media and Science a wedding made in Heaven...
 or in Hell?Erik Duval
 
Information visualisation: 
Data ink design principles
Information visualisation: 
Data ink design principlesInformation visualisation: 
Data ink design principles
Information visualisation: 
Data ink design principlesErik Duval
 
InfoVis1415: slides sessie 8, 20 april 2015
InfoVis1415: slides sessie 8, 20 april 2015InfoVis1415: slides sessie 8, 20 april 2015
InfoVis1415: slides sessie 8, 20 april 2015Erik Duval
 
A short history (and even shorter future)
 of information visualisation
A short history (and even shorter future)
 of information visualisationA short history (and even shorter future)
 of information visualisation
A short history (and even shorter future)
 of information visualisationErik Duval
 
InfoVis1415: slides sessie 7, 30 March 2015
InfoVis1415: slides sessie 7, 30 March 2015InfoVis1415: slides sessie 7, 30 March 2015
InfoVis1415: slides sessie 7, 30 March 2015Erik Duval
 
InfoVis1415: slides sessie 6, 23 March 2015
InfoVis1415: slides sessie 6, 23 March 2015InfoVis1415: slides sessie 6, 23 March 2015
InfoVis1415: slides sessie 6, 23 March 2015Erik Duval
 
History of Human Computer Interaction
History of Human Computer InteractionHistory of Human Computer Interaction
History of Human Computer InteractionErik Duval
 
InfoVis1415: slides sessie 5, 9 March 2015
InfoVis1415: slides sessie 5, 9 March 2015InfoVis1415: slides sessie 5, 9 March 2015
InfoVis1415: slides sessie 5, 9 March 2015Erik Duval
 
InfoVis1415: slides sessie 4, 2 March 2015
InfoVis1415: slides sessie 4, 2 March 2015InfoVis1415: slides sessie 4, 2 March 2015
InfoVis1415: slides sessie 4, 2 March 2015Erik Duval
 
InfoVis1415: slides sessie 3, 23 Feb 2015
InfoVis1415: slides sessie 3, 23 Feb 2015InfoVis1415: slides sessie 3, 23 Feb 2015
InfoVis1415: slides sessie 3, 23 Feb 2015Erik Duval
 
InfoVis1415: slides sessie 2, 16 Feb 2015
InfoVis1415: slides sessie 2, 16 Feb 2015InfoVis1415: slides sessie 2, 16 Feb 2015
InfoVis1415: slides sessie 2, 16 Feb 2015Erik Duval
 
Technology that makes HUMANS smarter
Technology that makes HUMANS smarterTechnology that makes HUMANS smarter
Technology that makes HUMANS smarterErik Duval
 
InfoVis1415: slides sessie 1, 10 Feb 2015
InfoVis1415: slides sessie 1, 10 Feb 2015InfoVis1415: slides sessie 1, 10 Feb 2015
InfoVis1415: slides sessie 1, 10 Feb 2015Erik Duval
 
201502010 pen ocw_les1_erik
201502010 pen ocw_les1_erik201502010 pen ocw_les1_erik
201502010 pen ocw_les1_erikErik Duval
 

Mais de Erik Duval (20)

eCloud newspapers
eCloud newspaperseCloud newspapers
eCloud newspapers
 
InfoVis1415: slides sessie 12, 18 mei 2015
InfoVis1415: slides sessie 12, 18 mei 2015InfoVis1415: slides sessie 12, 18 mei 2015
InfoVis1415: slides sessie 12, 18 mei 2015
 
InfoVis1415: slides sessie 11, 11 mei 2015
InfoVis1415: slides sessie 11, 11 mei 2015InfoVis1415: slides sessie 11, 11 mei 2015
InfoVis1415: slides sessie 11, 11 mei 2015
 
InfoVis1415: slides sessie 10, 4 mei 2015
InfoVis1415: slides sessie 10, 4 mei 2015InfoVis1415: slides sessie 10, 4 mei 2015
InfoVis1415: slides sessie 10, 4 mei 2015
 
Evaluation
 of information visualisation
Evaluation
 of information visualisationEvaluation
 of information visualisation
Evaluation
 of information visualisation
 
InfoVis1415: slides sessie 9, 27 april 2015
InfoVis1415: slides sessie 9, 27 april 2015InfoVis1415: slides sessie 9, 27 april 2015
InfoVis1415: slides sessie 9, 27 april 2015
 
Social Media and Science a wedding made in Heaven...
 or in Hell?
Social Media and Science a wedding made in Heaven...
 or in Hell?Social Media and Science a wedding made in Heaven...
 or in Hell?
Social Media and Science a wedding made in Heaven...
 or in Hell?
 
Information visualisation: 
Data ink design principles
Information visualisation: 
Data ink design principlesInformation visualisation: 
Data ink design principles
Information visualisation: 
Data ink design principles
 
InfoVis1415: slides sessie 8, 20 april 2015
InfoVis1415: slides sessie 8, 20 april 2015InfoVis1415: slides sessie 8, 20 april 2015
InfoVis1415: slides sessie 8, 20 april 2015
 
A short history (and even shorter future)
 of information visualisation
A short history (and even shorter future)
 of information visualisationA short history (and even shorter future)
 of information visualisation
A short history (and even shorter future)
 of information visualisation
 
InfoVis1415: slides sessie 7, 30 March 2015
InfoVis1415: slides sessie 7, 30 March 2015InfoVis1415: slides sessie 7, 30 March 2015
InfoVis1415: slides sessie 7, 30 March 2015
 
InfoVis1415: slides sessie 6, 23 March 2015
InfoVis1415: slides sessie 6, 23 March 2015InfoVis1415: slides sessie 6, 23 March 2015
InfoVis1415: slides sessie 6, 23 March 2015
 
History of Human Computer Interaction
History of Human Computer InteractionHistory of Human Computer Interaction
History of Human Computer Interaction
 
InfoVis1415: slides sessie 5, 9 March 2015
InfoVis1415: slides sessie 5, 9 March 2015InfoVis1415: slides sessie 5, 9 March 2015
InfoVis1415: slides sessie 5, 9 March 2015
 
InfoVis1415: slides sessie 4, 2 March 2015
InfoVis1415: slides sessie 4, 2 March 2015InfoVis1415: slides sessie 4, 2 March 2015
InfoVis1415: slides sessie 4, 2 March 2015
 
InfoVis1415: slides sessie 3, 23 Feb 2015
InfoVis1415: slides sessie 3, 23 Feb 2015InfoVis1415: slides sessie 3, 23 Feb 2015
InfoVis1415: slides sessie 3, 23 Feb 2015
 
InfoVis1415: slides sessie 2, 16 Feb 2015
InfoVis1415: slides sessie 2, 16 Feb 2015InfoVis1415: slides sessie 2, 16 Feb 2015
InfoVis1415: slides sessie 2, 16 Feb 2015
 
Technology that makes HUMANS smarter
Technology that makes HUMANS smarterTechnology that makes HUMANS smarter
Technology that makes HUMANS smarter
 
InfoVis1415: slides sessie 1, 10 Feb 2015
InfoVis1415: slides sessie 1, 10 Feb 2015InfoVis1415: slides sessie 1, 10 Feb 2015
InfoVis1415: slides sessie 1, 10 Feb 2015
 
201502010 pen ocw_les1_erik
201502010 pen ocw_les1_erik201502010 pen ocw_les1_erik
201502010 pen ocw_les1_erik
 

Entiteit-Relatie Model

  • 1. Gegevensbanken entiteit-relatie model Prof. Erik Duval 2009 - 2010 1
  • 3. 3
  • 4. ontwerp van een gegevensbank • conceptuele gegevensmodellen • voorbeeld • E-R model • E-R diagrammen • ontwerpkeuzes • niet-binaire relaties 4
  • 6. 6
  • 7. analyse • welke behoeften? welk gegevens zijn hiervoor nodig? 6
  • 8. analyse • welke behoeften? welk gegevens zijn hiervoor nodig? • conceptueel ontwerp • beschrijving van gegevenstypes, relaties, restricties en operaties • volgens hoog-niveau gegevensmodel 6
  • 9. analyse • welke behoeften? welk gegevens zijn hiervoor nodig? • conceptueel ontwerp • beschrijving van gegevenstypes, relaties, restricties en operaties • volgens hoog-niveau gegevensmodel • transformatie naar implementatiemodel • conceptueel schema volgens model van DBMS 6
  • 10. analyse • welke behoeften? welk gegevens zijn hiervoor nodig? • conceptueel ontwerp • beschrijving van gegevenstypes, relaties, restricties en operaties • volgens hoog-niveau gegevensmodel • transformatie naar implementatiemodel • conceptueel schema volgens model van DBMS • fysisch ontwerp • intern schema volgens model van DBMS 6
  • 11. 7
  • 13. 9
  • 14. bedoeling: • relevant deel van de werkelijkheid beschrijven • objecten + feiten 9
  • 15. bedoeling: • relevant deel van de werkelijkheid beschrijven • objecten + feiten • beschrijving = schema • elke groep gebruikers heeft eigen schema • alle schema's samen: infologisch schema 9
  • 16. bedoeling: • relevant deel van de werkelijkheid beschrijven • objecten + feiten • beschrijving = schema • elke groep gebruikers heeft eigen schema • alle schema's samen: infologisch schema • modellering gebruikt abstractie • details weggelaten • algemene, gemeenschappelijke eigenschappen en feiten 9
  • 17. 10
  • 18. waarom • sluit nauwer aan bij realiteit dan een implementatiemodel • bevat meer informatie omtrent betekenis van objecten dan implementatiemodellen • ... en minder informatie omtrent details van implementatie 10
  • 19. waarom • sluit nauwer aan bij realiteit dan een implementatiemodel • bevat meer informatie omtrent betekenis van objecten dan implementatiemodellen • ... en minder informatie omtrent details van implementatie • gebruikte model: entiteit-relatie-model • objecten • verbanden tussen objecten (relaties) • eigenschappen (attributen) • waardenverzamelingen (domeinen) 10
  • 20. 11
  • 21. entiteiten ∈ entiteitstype 11
  • 22. entiteiten ∈ entiteitstype • relaties ∈ relatietype 11
  • 23. entiteiten ∈ entiteitstype • relaties ∈ relatietype • attributen: waarden ∈ domein 11
  • 24. entiteiten ∈ entiteitstype • relaties ∈ relatietype • attributen: waarden ∈ domein 11
  • 25. entiteiten ∈ entiteitstype • relaties ∈ relatietype • attributen: waarden ∈ domein • sleutel • identificator v.e. entiteitstype / relatietype • waarde van sleutel bepaalt eenduidig de entiteit / relatie 11
  • 27. ...
  • 28. bedrijf is georganiseerd in departementen • een departement heeft naam, nummer, een of meer locaties, departementshoofd (sinds een bepaalde datum) • elk departement controleert een aantal projecten elk project heeft naam, nummer, 1 locatie • voor elke werknemer • naam, ID, adres, salaris, geslacht, geboortedatum, #uren per week besteed aan elk project, onmiddellijke overste (supervisor) • een werknemer hoort bij 1 departement, maar kan aan meerdere projecten werken die niet noodzakelijk door 1 departement gecontroleerd worden • voor elke werknemer bovendien van de personen ten laste • naam, geslacht, geboortedatum, relatie tot werknemer
  • 29. schema: mini-wereld • entiteit: object (fysisch of conceptueel) • entiteit type: klasse • attribuut: eigenschap • samengesteld / enkelvoudig (atomair) • eenwaardig / meerwaardig • expliciet voorgesteld / afgeleid • domein (= mogelijke waarden) • null-waarden: • "heeft geen waarde" : niet van toepassing / onbekend • nesten van samengestelde / meerwaardige attributen
  • 30.
  • 31.
  • 32.
  • 33.
  • 34. sleutel • attribuut waarvan de waarden verschillen voor elke verschillende entiteit, in elke mogelijke instantie • soms combinatie van attributen • soms meer dan één sleutel 20
  • 35. ontwerp van ER schema identificeer • entiteitstypes • attributen van elk entiteitstype • sleutelattributen 21
  • 36. 22
  • 37. Fname Minit Lname Salary Name Sex Address Ssn EMPLOYEE Bdate 22
  • 38. Fname Minit Lname Number Salary Name Name Locations Sex Address Ssn EMPLOYEE DEPARTMENT Bdate 22
  • 39. Fname Minit Lname Number Salary Name Name Locations Sex Address Ssn EMPLOYEE DEPARTMENT Bdate PROJECT Name Location Number 22
  • 40. Fname Minit Lname Number Salary Name Name Locations Sex Address Ssn EMPLOYEE DEPARTMENT Bdate PROJECT Name Location DEPENDENT Number Name Relationship Sex Birthdate 22
  • 41. relatie • relatietype = verzameling verbanden (relaties) over entiteitstypes E1, ..., En • graad = aantal betrokken entiteitstypes • binair, ternair, ... • 1 entiteitstype meerdere keren: recursief relatietype • vb. SUPERVISION • entiteitstype speelt rol in een relatie 23
  • 42. 24
  • 43. 25
  • 44. 26
  • 45. ontwerp van ER schema identificeer • entiteitstypes en attributen van elk entiteitstype • sleutelattributen • relatietypes en attributen van elk relatietype • connectiviteit en deelnamebeperkingen • eventuele afgeleide attributen in entiteitstypes • vb: aantal werknemers in een departement 27
  • 46. 28
  • 47. Fname Minit Lname Salary Name Sex Address Ssn EMPLOYEE Bdate 28
  • 48. Fname Minit Lname Number Salary Name Name Locations Sex Address Ssn EMPLOYEE DEPARTMENT Bdate 28
  • 49. Fname Minit Lname Number Salary Name Name Locations Sex Address Ssn EMPLOYEE DEPARTMENT Bdate PROJECT Name Location Number 28
  • 50. Fname Minit Lname Number Salary Name Name Locations Sex Address Ssn EMPLOYEE DEPARTMENT Bdate PROJECT Name Location DEPENDENT Number Name Relationship Sex BirthDate 28
  • 51. Fname Minit Lname Number Salary Name Name WORKS_FOR Locations Sex Address Ssn EMPLOYEE DEPARTMENT Bdate PROJECT Name Location DEPENDENT Number Name Relationship Sex BirthDate 28
  • 52. Fname Minit Lname Number Salary Name Name WORKS_FOR Locations Sex Address Ssn StartDate EMPLOYEE DEPARTMENT Bdate MANAGES PROJECT Name Location DEPENDENT Number Name Relationship Sex BirthDate 28
  • 53. Fname Minit Lname Number Salary Name Name WORKS_FOR Locations Sex Address Ssn StartDate EMPLOYEE DEPARTMENT Bdate MANAGES CONTROLS PROJECT Name Location DEPENDENT Number Name Relationship Sex BirthDate 28
  • 54. Fname Minit Lname Number Salary Name Name WORKS_FOR Locations Sex Address Ssn StartDate EMPLOYEE DEPARTMENT Bdate MANAGES CONTROLS SUPERVISES PROJECT Name Location DEPENDENT Number Name Relationship Sex BirthDate 28
  • 55. Fname Minit Lname Number Salary Name Name WORKS_FOR Locations Sex Address Ssn StartDate EMPLOYEE DEPARTMENT Bdate MANAGES CONTROLS SUPERVISES HAS_DEP. PROJECT Name Location DEPENDENT Number Name Relationship Sex BirthDate 28
  • 56. Fname Minit Lname Number Salary Name Name WORKS_FOR Locations Sex Address Ssn StartDate EMPLOYEE DEPARTMENT Bdate MANAGES Hours CONTROLS WORKS_ON SUPERVISES HAS_DEP. PROJECT Name Location DEPENDENT Number Name Relationship Sex BirthDate 28
  • 57. beperkingen op relatietypes • connectiviteit ("cardinality ratio") • voor binaire relatietypes: 1:1, 1:n, m:n • vb. werknemer behoort bij precies één departement • ternaire, ... relatietypes: meer mogelijkheden • deelnamebeperking • totale / partiële deelname • vb. moet iedereen bij een departement behoren? • voor binaire relatietypes: T-T, T-P, P-P • totale deelname = "bestaansafhankelijkheid" 29
  • 58. 1:n en totaal voor employee en department 30
  • 59. 1:n en partieel voor supervisor en supervisee rol 31
  • 60. 1:1, totaal voor department en partieel voor employee 32
  • 61. attributen van relatietypes • vb. aantal uren / week dat werknemer aan project werkt • 1 : 1 ➡ attribuut kan bij een van de entiteitstypes • 1 : n ➡ attribuut kan bij entiteitstype aan n-zijde • m : n ➡ attribuut kan niet bij entiteitstypes • moet bij relatietype zelf • vb: WORKS_ON: Hours 33
  • 62. Fname Minit Lname Number Salary Name Name N WORKS_FOR 1 Locations Sex Address Ssn StartDate EMPLOYEE DEPARTMENT 1 Bdate 1 1 MANAGES Hours CONTROLS supervisor supervisee 1 N 1 N N SUPERVISES WORKS_ON M HAS_DEP. PROJECT N Name Location DEPENDENT Number Name Relationship Sex BirthDate 34
  • 63. zwakke entiteitstypes • zonder eigen sleutel • identificatie via entiteit van ander entiteitstype • identificerende entiteit = "eigenaar", identificerende relatie • steeds totale deelname in identificerende relatie • partiële sleutel • identificeert entiteit binnen entiteiten met zelfde eigenaar • partiële sleutel = "discriminator" • vb : DEPENDENT 35
  • 64. bestaansafhankelijkheid • bestaan ene hangt af van bestaan van andere • ondergeschikte entiteit - dominante entiteit • identificatieafhankelijkheid • kan niet geïdentificeerd worden met eigen attributen • = zwakke entiteit • vb. straat ← gemeente ← land • vaak samen, maar niet altijd 36
  • 65. – ENTITEIT : • enkelvoud (bv. PERSOON, niet PERSONEN) – RELATIE : • vervoegd werkwoord – Attribuut – Sleutelattribuut – rolnaam 37
  • 66. 38
  • 67. 39
  • 68. alternatieve notatie (min,max) annotatie bij rol hoe vaak kan een entiteit die rol spelen in een relatie? min = 0 → partieel min > 0 → totaal 40
  • 69. Fname Minit Lname Number Salary Name Name WORKS_FOR (4,N) Locations Sex Address (1,1) Ssn StartDate EMPLOYEE DEPARTMENT (0,1) (1,1) (0,N) Bdate MANAGES (0,1) hours CONTROLS (0,N) supervisee (1,N) supervisor (0,N) (1,1) WORKS_ON (1,N) SUPERVISES HAS_DEP. PROJECT (1,1) Name Location DEPENDENT Number Name Relationship Sex BirthDate 41
  • 70. ontwerpkeuzes • attribuut verwijst naar ander entiteitstype ➡ relatie • vb. manager als attribuut bij DEPARTMENT of als relatie ts. DEPARTMENT en EMPLOYEE • attribuut bij verschillende entiteitstypes ➡ entiteitstype • vb. STUDENT, INSTRUCTOR en COURSE een attribuut ‘Departement’ ➡ entiteit DEPARTMENT • entiteitstype met één attribuut met één entiteitstype relatie ➡ attribuut • vb. entiteitstype DEPARTMENT met slechts één attribuut, en enkel relatie met STUDENT ➡attribuut 42
  • 72. niet-binaire relaties • vb. van ternaire relatie: SUPPLY • leverancier levert onderdelen voor project • SUPPLIER, PART en PROJECT in relatie SUPPLY • connectiviteit en deelnamebeperking • ingewikkelder, met (min, max) notatie • is ternaire relatie ook via binaire relaties voor te stellen? 44
  • 73. 45
  • 74. Quantity SuppNo ProjNo (0,N) (1,N) SUPPLIER SUPPLIES_FOR PROJECT (0,N) PartNo PART 46
  • 75. een ternair relatietype vervangen door drie binaire relatietypes? SuppNo ProjNo Quantity SUPPLIER (0,N) (1,N) PROJECT SUPPLIES_FOR (0,N) PART PartNo 47
  • 76. een ternair relatietype vervangen door drie binaire relatietypes? SuppNo ProjNo Quantity SUPPLIER (0,N) (1,N) PROJECT SUPPLIES_FOR (0,N) CAN_SUPPLY PART PartNo 47
  • 77. een ternair relatietype vervangen door drie binaire relatietypes? SuppNo ProjNo Quantity SUPPLIER (0,N) (1,N) PROJECT SUPPLIES_FOR (0,N) CAN_SUPPLY PART USES PartNo 47
  • 78. een ternair relatietype vervangen door drie binaire relatietypes? PARTICIPATES SuppNo ProjNo Quantity SUPPLIER (0,N) (1,N) PROJECT SUPPLIES_FOR (0,N) CAN_SUPPLY PART USES PartNo 47
  • 79. 48
  • 80. 49