1 / 25

Databases I (H.9.1-2) Van EER naar relationeel

versie 2003. Databases I (H.9.1-2) Van EER naar relationeel. Wiebren de Jonge Vrije Universiteit, Amsterdam. Waar in DB ontwerp proces? Nu stap 3a. Miniworld. 1. REQUIREMENTS COLLECTION AND ANALYSIS. Functional Requirements. Data Requirements. 2b. 2a. FUNCTIONAL DESIGN.

adelio
Télécharger la présentation

Databases I (H.9.1-2) Van EER naar relationeel

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. Voorbeeld ER-diagram (Fig. 3.15)

  4. Relationeel schema diagram (Fig. 7.7)

  5. FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY 1 Voorbeeld mapping regular entity type fname minit lname name sex ssn address EMPLOYEE bdate salary EMPLOYEE 1 was oorspronkelijk composite attribuut

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

  7. Voorbeeld mapping weak entity type fname minit lname bdate relationship sex ssn name sex DEPENDENTS_OF DEPENDENT EMPLOYEE name bdate salary address DEPENDENT ESSN DEPENDENT_NAME SEX BDATE RELATIONSHIP 1 1 partial key weak entity N.B. identifying rel.ship is nu in feite ook al verwerkt FK naar owner (EMPLOYEE)

  8. 2. Mapping weak entity types Voor weak entity types E: • maak een tabel met als attributen alle simple attributes van E (N.B. ook de simple attributes die behoren tot evt. composite attributes) • voeg voor elke owner aan deze tabel een FK (foreign key) toe die verwijst naar die owner (hiermee is de identifying relationship afgehandeld) • laat eventuele multivalued attributes nog even achterwege • 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 • specificeer bij FK’s naar owners: “cascade” of “restricted” (beslist niet: “nullify” !!)

  9. Voorbeeld mapping binary 1:1 rel.ship type fname minit lname number startdate 1 sex locations ssn name name 2 MANAGES EMPLOYEE DEPARTMENT (0,1) (1,1) dus: total participation van DEPARTMENT dus: partial participation van EMPLOYEE bdate salary address attribuut van relationship DEPARTMENT DNAME DNUMBER MGRSSN MGRSTARTDATE 2 1 FK naar “EMPLOYEE” (hier: no nulls) Merk op: “locations” wordt niet in tabel “DEPARTMENT” opgenomen!

  10. 3. Mapping binary 1:1 relationship types Voor binaire 1:1 relationship types: • kies één van de participerende entity types (zeg: E1),zo mogelijk (resp. liefst) één met totale participatie • 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 • als E1 totaal participeert in deze relationship, specificeerdan bij de genoemde FK “no nulls” (i.e. “nulls not allowed”)

  11. FNAME MINIT LNAME SSN BDATE ADDRESS SEX SALARY 1 Voorbeeld mapping binary 1:N rel.ship type fname minit lname number 1 sex locations ssn name name 2 WORKS_FOR EMPLOYEE DEPARTMENT (4,N) (1,1) bdate salary address deze hadden we al EMPLOYEE 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: • 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 • als het entiteitstype “aan de N-kant” totaal participeertin deze relationship, specificeer dan bij de genoemdeFK “no nulls” (oftewel “nulls not allowed”)

  13. Voorbeeld mapping binary N:M rel.ship type fname minit lname number 1 hours sex location ssn name name 2 WORKS_ON EMPLOYEE PROJECT (1,N) (1,N) bdate salary address WORKS_ON ESSN PNO HOURS 1 1 attribuut van relationship type FK naar “PROJECT” FK naar “EMPLOYEE”

  14. 5. Mapping binary M:N relationship types Voor binaire M:N relationship types: • maak een tabel (zeg: R) met daarin: • foreign keys naar de tabellen aan de M- en de N-kant • eventuele attributen van de relationship • kies als primary key van R de combinatie van alle attributen van de bovengenoemde foreign keys • 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 adres ssn naam adres naam LID_VAN M N PERSOON PARTIJ PARTIJ PERSOON ADRES NAAM SSN NAAM ADRES PERSOON_PARTIJ 1 1 SSN_PERSOON NAAM_PARTIJ 1 1 FK FK

  16. Alternatieve mapping binary N:1 rel.ship types adres ssn naam adres naam LID_VAN N 1 PERSOON PARTIJ PERSOON PARTIJ 1. SSN NAAM ADRES NAAM_PARTIJ ADRES NAAM FK 1 1 voordelen: - relatief “eenvoudig en snel” - indien persoon totale participatie heeft: geen nulls en geen verspilling opslagruimte PARTIJ PERSOON 2. ADRES NAAM SSN NAAM ADRES PERSOON_PARTIJ 1 1 SSN_PERSOON NAAM_PARTIJ FK FK 1 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 quantity s# name j# name SUPPLY SUPPLIER PROJECT p# PART name SUPPLY SNO JNO PNO QUANTITY 1 1 1

  18. 7. Mapping n-ary relationship types (n > 2) Voor n-aire relationship types (n > 2): • 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 • kies als primary key van R de attributen van de foreign keysmet “cardinaliteitsconstraint” N (oftewel “many”)

  19. Voorbeeld mapping multi-valued attribute number 1 locations name WORKS_FOR 2 CONTROLS DEPARTMENT MANAGES dit hadden we al DEPARTMENT DNAME DNUMBER MGRSSN MGRSTARTDATE 2 1 DEPT_LOCATIONS dit nu toevoegen DNUMBER DLOCATION 1 1 FK

  20. 6. Mapping multivalued attributes Voor multivalued attributes: • 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 • de primary key van R bestaat uit de attributen van F en A

  21. Voorbeeld mapping subclass entities (1) ssn name bdate address EMPLOYEE typing speed d specialism SECRETARY SALESMAN ENGINEER limit 1) EMPLOYEE NAME SSN BDATE ADDRESS EMP-TYPE 1 SECRETARY SALESMAN ENGINEER SSN TSPEED SSN LIMIT SSN SPECIALISM 1 1 1

  22. Voorbeeld mapping subclass entities (2) 2) SECRETARY SALESMAN NAME SSN BDATE ADDRESS TSPEED NAME SSN BDATE ADDRESS LIMIT 1 1 ENGINEER NAME SSN BDATE ADDRESS SPECIALISM 1 3) EMPLOYEE NAME SSN BDATE ADDRESS EMP_TYPE TSPEED LIMIT SPECIALISM 1 4) EMPLOYEE SPEC NAME SSN BDATE ADDRESS SEC_FLAG TSPEED LIMIT SALE_FLAG ENG_FLAG 1

  23. 8a. Mapping subclass entity types Voor iedere subclass entity (Sub) van een superclass entity (Super): • maak een tabel met daarin: • de local attributes (single-valued) van Sub • een foreign key naar Super • 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# j# quantity N N 1 1 SUPPLIER SS SUPPLY SJ PROJECT N name name SP 1 p# PART name stap 1a: reguliere entiteiten SUPPLIER PART PROJECT SNO NAME PNO NAME JNO NAME 1 1 1 stap 1c: zwakke entiteiten SUPPLY SNO PNO JNO QUANTITY 1 1 1 stap 2b: N:1 relationships [geen verandering, want de toe te voegen foreign keys zitten al in SUPPLY!]

More Related