De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Databases I (H.9.1-2) Van EER naar relationeel Wiebren de Jonge Vrije Universiteit, Amsterdam versie 2003.

Verwante presentaties


Presentatie over: "Databases I (H.9.1-2) Van EER naar relationeel Wiebren de Jonge Vrije Universiteit, Amsterdam versie 2003."— Transcript van de presentatie:

1 Databases I (H.9.1-2) Van EER naar relationeel Wiebren de Jonge Vrije Universiteit, Amsterdam versie 2003

2 Waar in DB ontwerp proces? Nu stap 3a. Miniworld REQUIREMENTS COLLECTION AND ANALYSIS CONCEPTUAL DB-DESIGNFUNCTIONAL DESIGN Data RequirementsFunctional Requirements High-level Transaction SpecifiationConceptual Schema (in a high-level data model) LOGICAL DB-DESIGN (DATA MODEL MAPPING) Conceptual Schema in DBMS independent data model LOGICAL DB-DESIGN (DBMS MAPPING) Logical (Conceptual) Schema (in the data model of a specific DBMS) PHYSICAL DB-DESIGN Internal Schema (for the same DBMS) DBMS & implementation data model independent Implementation data model specific DBMS specific APPLICATION PROGRAM DESIGN TRANSACTION IMPLEMENTATION Application Programs 1. 2a.2b. 3a. 3b. 4a. 4b. 5.

3 Voorbeeld ER-diagram (Fig. 3.15)

4 Relationeel schema diagram (Fig. 7.7)

5 Voorbeeld mapping regular entity type EMPLOYEE bdate ssn name fnameminitlname sex address salary 1 FNAMEMINITLNAMESSN 1 BDATEADDRESSSEXSALARY was oorspronkelijk composite attribuut EMPLOYEE

6 1. Mapping regular entity types Voor elk regular (non-weak, non-subclass) entity type E: u maak een tabel met als attributen alle simple attributes van E ( N.B. ook de simple attributes die behoren tot evt. composite attributes ) u laat eventuele multivalued attributes nog even achterwege u kies één van de keys van E als primary key

7 Voorbeeld mapping weak entity type DEPENDENT name sex bdaterelationship DEPENDENTS_OF EMPLOYEE bdate ssnname fnameminitlname sex addresssalary ESSNDEPENDENT_NAME 1 SEXBDATERELATIONSHIP DEPENDENT 1 partial key weak entity FK naar owner (EMPLOYEE) N.B. identifying rel.ship is nu in feite ook al verwerkt

8 2. Mapping weak entity types Voor weak entity types E: u maak een tabel met als attributen alle simple attributes van E ( N.B. ook de simple attributes die behoren tot evt. composite attributes ) u voeg voor elke owner aan deze tabel een FK (foreign key) toe die verwijst naar die owner ( hiermee is de identifying relationship afgehandeld) u laat eventuele multivalued attributes nog even achterwege u kies als primary key de combinatie van: –de attributen van de partial key (tenminste, als die bestaat) –de attributen van elke foreign key naar een owner u specificeer bij FK’s naar owners: “cascade” of “restricted” (beslist niet: “nullify” !!)

9 Voorbeeld mapping binary 1:1 rel.ship type EMPLOYEE bdate ssnname fnameminitlname sex addresssalary MANAGES startdate DEPARTMENT name number locations DNAMEDNUMBER 2 MGRSSNMGRSTARTDATE 1 2 1 DEPARTMENT attribuut van relationship FK naar “EMPLOYEE” (hier: no nulls) Merk op: “locations” wordt niet in tabel “DEPARTMENT” opgenomen! (0,1) (1,1) dus: partial participation van EMPLOYEE dus: total participation van DEPARTMENT

10 3. Mapping binary 1:1 relationship types Voor binaire 1:1 relationship types: u kies één van de participerende entity types (zeg: E1), zo mogelijk (resp. liefst) één met totale participatie u voeg aan de tabel (zeg: R1) van dit entiteitstype E1 toe: –een foreign key naar de tabel van het andere entiteitstype –eventuele attributen van de relationship u als E1 totaal participeert in deze relationship, specificeer dan bij de genoemde FK “no nulls” (i.e. “nulls not allowed”)

11 Voorbeeld mapping binary 1:N rel.ship type EMPLOYEE bdate ssnname fnameminitlname sex addresssalary WORKS_FOR DEPARTMENT name number locations 2 1 (1,1) (4,N) FNAMEMINITLNAMESSN 1 BDATEADDRESSSEXSALARY EMPLOYEE deze hadden we al DNO nu toevoegen: FK naar “DEPARTMENT” (specificeer “no nulls” vanwege total partic.)

12 4. Mapping binary N:1 relationship types Voor binaire N:1 (resp. 1:N) relationship types: u voeg in de tabel “aan de N-kant” het volgende toe: –een FK (foreign key) naar de tabel “aan de 1-kant” –eventuele attributen van de relationship u als het entiteitstype “aan de N-kant” totaal participeert in deze relationship, specificeer dan bij de genoemde FK “no nulls” (oftewel “nulls not allowed”)

13 Voorbeeld mapping binary N:M rel.ship type bdate ssnname fnameminitlname sex addresssalary WORKS_ON PROJECT name number location (1,N) EMPLOYEE 2 1 hours ESSNPNO 1 1 WORKS_ON HOURS FK naar “EMPLOYEE” FK naar “PROJECT” attribuut van relationship type

14 5. Mapping binary M:N relationship types Voor binaire M:N relationship types: u maak een tabel (zeg: R) met daarin: –foreign keys naar de tabellen aan de M- en de N-kant –eventuele attributen van de relationship u kies als primary key van R de combinatie van alle attributen van de bovengenoemde foreign keys u specificeer bij de genoemde FK’s “cascade” of “restricted” N.B.:1:1 en N:1 relationship types kunnen evt. op soortgelijke wijze afgehandeld worden !! (Bij 1:1 zijn beide FK’s dan een sleutel en wordt eentje de PK. Bij N:1 is dan alleen de FK “naar de N-kant” een sleutel en dus PK.)

15 Extra voorbeeld mapping binary M:N rel.ship ssnnaamadres LID_VAN PARTIJ naam adres PERSOON MN SSNNAAM 1 ADRES SSN_PERSOON 1 ADRES NAAM NAAM_PARTIJ 1 1 PERSOON PERSOON_PARTIJ PARTIJ FK

16 Alternatieve mapping binary N:1 rel.ship types ssnnaamadres LID_VAN PARTIJ naam adres PERSOON N1 SSNNAAM 1 ADRES SSN_PERSOON 1 ADRES NAAM NAAM_PARTIJ 1 PERSOON PERSOON_PARTIJ PARTIJ FK SSNNAAM 1 ADRES PERSOON 1. 2. NAAM_PARTIJADRES NAAM 1 PARTIJ FK voordelen: - relatief “eenvoudig en snel” - indien persoon totale participatie heeft: geen nulls en geen verspilling opslagruimte voordelen: - geen nulls, ook niet indien persoon partiële participatie heeft !! - minder opslagruimte nodig indien persoon (zeer) partiële participatie heeft - flexibel (als ’t later een N:M rel.ship wordt, dan slechts: kies nieuwe, samengestelde PK)

17 Voorbeeld mapping n-ary (n>2) rel.ship type s#name SUPPLY PROJECT j#name SUPPLIER PARTnamep# SNO 1 JNO 1 PNO 1 QUANTITY SUPPLY quantity

18 7. Mapping n-ary relationship types (n > 2) Voor n-aire relationship types (n > 2): u maak een tabel (zeg: R) met daarin: –een foreign key naar iedere tabel van een in dit relationship type participerend entiteitstype –eventuele attributen van dit relationship type u kies als primary key van R de attributen van de foreign keys met “cardinaliteitsconstraint” N (oftewel “many”)

19 Voorbeeld mapping multi-valued attribute DEPARTMENT name number locations 2 1 WORKS_FOR MANAGES CONTROLS DNAMEDNUMBER 2 MGRSSNMGRSTARTDATE 1 DEPARTMENT dit hadden we al DNUMBERDLOCATION 1 1 DEPT_LOCATIONS FK dit nu toevoegen

20 6. Mapping multivalued attributes Voor multivalued attributes: u maak voor ieder multi-valued attribute (A) een aparte tabel (R) met daarin: –het single-valued attribuut corresponderend met A –een foreign key (F) naar de tabel van het entiteitstype met dit multi-valued attribute A u de primary key van R bestaat uit de attributen van F en A

21 Voorbeeld mapping subclass entities (1) EMPLOYEE bdatessnnameaddress d SALESMANENGINEERSECRETARY specialism limit typing speed NAMESSN 1 BDATE EMPLOYEE1) ADDRESS TSPEED SECRETARY SSN 1 LIMIT SALESMAN SSN 1 SPECIALISM ENGINEER SSN 1 EMP-TYPE

22 Voorbeeld mapping subclass entities (2) NAMESSN 1 BDATE SECRETARY2) ADDRESSTSPEEDNAMESSN 1 BDATE SALESMAN ADDRESSLIMIT NAMESSN 1 BDATE ENGINEER ADDRESSSPECIALISM EMPLOYEE3) NAMESSN 1 BDATEADDRESSTSPEED EMP_TYPE LIMITSPECIALISM EMPLOYEE4) NAMESSN 1 BDATEADDRESSTSPEED SEC_FLAG LIMIT SPEC SALE_FLAGENG_FLAG

23 8a. Mapping subclass entity types Voor iedere subclass entity (Sub) van een superclass entity (Super): u maak een tabel met daarin: –de local attributes (single-valued) van Sub –een foreign key naar Super u de primary key van Sub bestaat uit de attributes van de foreign key naar Super (i.e. Sub heeft dezelfde PK als Super)

24 Volgorde uitvoeren stappen 1.definieer tabellen voor: a.reguliere entiteiten (boek: step 1) b.subclass entiteiten (boek: step 8a) c.zwakke entiteiten (boek: step 2) 2.voeg aan de tabellen van de entiteiten extra attributen toe voor: a.binaire 1:1 relationships (boek: step 3) b. binaire 1:N relationships (boek: step 4) 3.voeg extra tabellen toe voor: a.binaire N:M relationships (boek: step 5) b.n-aire relationships, n>2 (boek: step 7) 4.voeg extra tabellen toe voor: multivalued attributes (boek: step 6)

25 Voorbeeld ternaire rel.ship als weak entity s# name SS PROJECT j# name SUPPLIER PARTnamep# SNO 1 PNO 1 JNO 1 QUANTITY SUPPLY quantity SJ SP N N N 1 1 1 stap 1a: reguliere entiteiten SUPPLIER SNO 1 NAME PART PNO 1 NAME PROJECT JNO 1 NAME stap 1c: zwakke entiteiten stap 2b: N:1 relationships [geen verandering, want de toe te voegen foreign keys zitten al in SUPPLY!]


Download ppt "Databases I (H.9.1-2) Van EER naar relationeel Wiebren de Jonge Vrije Universiteit, Amsterdam versie 2003."

Verwante presentaties


Ads door Google