14
CS485 – E/R to Relational Notation BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

Embed Size (px)

Citation preview

Page 1: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 1

BACS 485

Translating

E/R to Relational Notation

Page 2: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 2

Relational Notation

Relational Notation is a shorthand way to represent E/R diagrams. It is a half-way step between an abstract tool (i.e., E/R diagrams) and an implementation specific tool (i.e., SQL Create Table commands). The format is as follows:

Table-name(key-attribute, attribute-1,… attribute-N)

Page 3: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 3

Relational Notation

The basic rules of translating E/R diagrams to Relational Notation are given below:

Each entity becomes a table Each attribute on the table becomes an attribute on the table Primary keys are underlined Foreign keys are underlined with a dashed line In 1:1, the foreign key can be on either side of the relation (context

dependent) In 1:N, the foreign key goes on the ‘N’ side In M:N, the relation becomes a table and the key for the new table is

the concatenated primary keys of the original tables In sub-type/super-type, the primary key of the sub-type(s) is the same

as the super-type (thus, no “foreign key”)

Page 4: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 4

1:1E/R to Relational Notation

Translates to 2 tables:Table1 (A,B,C,D) OR Table1 (A,B,C)Table2 (D,E,F) Table2 (D,E,F,A)

pick one depending upon context, dashed underlined letter is foreign key

B

Table1 Table2Rel

A C ED F

Page 5: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 5

1:1Relational Notation to E/R

Translate from 2 tables:

Table1 (X,Y,Z) OR Table1 (X,Y,Z,L)

Table2 (L,M,N,X) Table2 (L,M,N)

pick one depending upon context, dashed underlined letter is foreign key

Y

Table1 Table2Rel

X Z ML N

Page 6: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 6

1:NE/R to Relational Notation

Translates to 2 tables:Table1 (A,B,C) Table2 (D,E,F,A) dashed underlined letter is foreign key

B

Table1 Table2Rel

A C ED F

Page 7: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 7

1:NRelational Notation to E/R

Translate from 2 tables:Table1 (X,Y,Z,L)Table2 (L,M,N)

dashed underlined letter is foreign key

Y

Table1 Table2Rel

X Z ML N

Page 8: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 8

Simple M:NE/R to Relational Notation

Translates to 3 tables:Table1 (A,B,C) Table2 (D,E,F)Table3 (A,D) Notice that there is no foreign key

B

Table1 Table2Rel

A C ED F

Page 9: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 9

Simple M:NRelational Notation to E/R

Translate from 3 tables:

Table1 (X,Y,Z)

Table2 (L,M,N)

Table3 (X,L)

Y

Table1 Table2Rel

X Z ML N

Page 10: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 10

More Complex M:NE/R to Relational Notation

Translates to 3 tables:Table1 (A,B,C) Table2 (D,E,F)Table3 (A,D,X) Notice that relationship attribute is attached to new table

B

Table1 Table2Rel

A C ED F

X

Page 11: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 11

More Complex M:NRelational Notation to E/R

Translate from 3 tables:

Table1 (X,Y,Z)

Table2 (L,M,N)

Table3 (X,L,P)

Y

Table1 Table2Rel

X Z ML N

P

Page 12: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 12

More Complex M:NE/R to Relational Notation

Translates to 3 tables:Table1 (A,B,C) Table2 (D,E,F)Table3 (A,D,X) Notice that relationship attribute is attached to new table

B

Table1 Table2Rel

A C ED F

X

Page 13: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 13

More Complex M:NE/R to Relational Notation

B

Table1 Table2Rel

A C ED F

I

Table3

H J

K

Translates to 4 tables:

Table1 (A,B,C) Table2 (D,E,F)Table3 (H,I,J)Table4 (A,D,H,K)

Page 14: BACS485 – E/R to Relational Notation1 BACS 485 Translating E/R to Relational Notation

BACS485 – E/R to Relational Notation 14

Sub-Type / Super-TypeE/R to Relational Notation

E

Table2Table3

D F IH

J

B

Table1

A C Translates to 3 tables:

Table1 (A,B,C) Table2 (A,D,E,F)Table3 (A,H,I,J)

Notice that Table2 and Table3 do not have a key in the E/R.