Difference between revisions of "6238 Databaser Agenda/ER til Relationel.pdf"
(→Step 6) |
(→Opgave) |
||
Line 91: | Line 91: | ||
==Opgave== | ==Opgave== | ||
Gentag med løsningen på Tennisopgaven | Gentag med løsningen på Tennisopgaven | ||
+ | |||
[[File:6238 Databaser Agenda ER til Relationel25.gif|611,25px]] | [[File:6238 Databaser Agenda ER til Relationel25.gif|611,25px]] |
Revision as of 14:41, 26 October 2015
Contents
6238 Databaser Agenda ER til Relationel
Fra ER-Diagram til Relationel model i 7 step
Denne slide viser et eksempel på hvordan man kommer fra ER-Diagram til den Relationeller model i 7 step. Eksemplet er en simpliceret udgave og kan i meget specielle tilfælde have fejl og mangler © Mercantec 2014
Den oprindelige udgave
STEP 1: For regular entity type E in ER schema, create a relation R that includes all the simple attributes, and component attributes of composite attributes. Select the primary key.
STEP 2: For weak entity type W in ER schema, with owner entity type E, create a relation R, include all simple attributes (or component attributes of composite attributes) of W as attributes of R. In addition, include the primary key attributes of the relation Q for the owner entity type E. Primary key is the combination of primary key of Q and partial key of R.
STEP 3: For 1:1 relationship X, suppose S and T are the relations for the entity types participating in it. Include primary key of T as foreign key of S. Include other attributes of the relationship X as attributes of S.
STEP 4: For 1:N relationship Y, suppose S relation corresponds to the entity type at the N-side, and T relation corresponds to the entity type at the other side. Include primary key of T as foreign key of S.
STEP 5: For M:N relationship Z, create a new relation R to represent Z. Include simple attributes of Z in R. Include the primary keys of S and T as foreign keys of R, their combination forms the primary key of R.
STEP 6: For multivalued attribute A, create a new relation R that includes an attribute corresponding to A. Include primary key of the relation of the entity type having A as an attribute. Primary key is their combination.
STEP 7: For n-ary relationship type X, and n>2, create a new relation R. Include primary key of each participating entity type's relation as foreign key of R. Include attributes of X as simple attributes of R.
Oplæg
Step 1
Lav en tabel for hver regulær entitet
Step 2
Lav en tabel for alle svage entiteter. Indsæt alle attributter I tabellen. Indsæt også en attribut for alle nøgler I den entitet den er svag overfor Primærnøglen er alle nøgle attributter fra den entitet den er svag overfor plus evt. ekstra nøgler.
Vi har ikke nogen svage entiteter i viste eksempel.
Step 3
Find alle 1:1 reletioner. Hvis der er tvungen deltagelse på en af siderne sættes FK nøglen på denne side. Hvis der er tvungen deltagelse på begge sider vælges en af siderne som nøgle bærer
Her indsættes Sælger som foreign key I Bil
Step 4
For alle 1:Mange relationer indsættes en FK nøgle på mange siden.
Her indsættes Sælger som FK på Kunde
Step 5
For alle mange til mange relationer oprettes en ny tabel. Tabellen kopierer nøgle fra begge tabeller som en ny sammensat nøgle.
Indsætter tabellen købes af
Step 6
For alle multivalue attributter oprettes en ny tabel. Lav en attribut i tabellen der peger på primærnøglen i den entitet den hører til.
Opretter tabellen TelefonNr og sætter Sælger som (FK)
Step 7
STEP 7: For n-ary relationship type X, and n>2, create a new relation R. Include primary key of each participating entity type's relation as foreign key of R. Include attributes of X as simple attributes of R.
Vi har ikke nogen n-ary relationer
Opgave
Gentag med løsningen på Tennisopgaven