6238 Databaser Agenda/ER til Relationel.pdf

From Teknologisk videncenter
Jump to: navigation, search

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

6238 Databaser Agenda ER til Relationel1.png

Step 1

Lav en tabel for hver regulær entitet

6238 Databaser Agenda ER til Relationel3.png 6238 Databaser Agenda ER til Relationel2.png

6238 Databaser Agenda ER til Relationel4.png 6238 Databaser Agenda ER til Relationel5.png

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

6238 Databaser Agenda ER til Relationel6.png 6238 Databaser Agenda ER til Relationel9.png

6238 Databaser Agenda ER til Relationel7.png 6238 Databaser Agenda ER til Relationel8.png

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

6238 Databaser Agenda ER til Relationel11.png 6238 Databaser Agenda ER til Relationel13.png

6238 Databaser Agenda ER til Relationel10.png 6238 Databaser Agenda ER til Relationel12.png

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

6238 Databaser Agenda ER til Relationel16.png 6238 Databaser Agenda ER til Relationel18.png

6238 Databaser Agenda ER til Relationel15.png 6238 Databaser Agenda ER til Relationel14.png 6238 Databaser Agenda ER til Relationel17.png

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)


6238 Databaser Agenda ER til Relationel19.png

6238 Databaser Agenda ER til Relationel21.png 6238 Databaser Agenda ER til Relationel23.png

6238 Databaser Agenda ER til Relationel20.png 6238 Databaser Agenda ER til Relationel24.png 6238 Databaser Agenda ER til Relationel22.png

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