140 likes | 308 Views
BACS 485. Translating E/R to Relational Notation. Relational Notation.
E N D
BACS 485 Translating E/R to Relational Notation
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)
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”)
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
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 underlinedletter is foreign key
1:NE/R to Relational Notation • Translates to 2 tables:Table1 (A,B,C) Table2 (D,E,F,A)dashed underlinedletter is foreign key
1:NRelational Notation to E/R • Translate from 2 tables: Table1 (X,Y,Z,L) Table2 (L,M,N) dashed underlinedletter is foreign key
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
Simple M:NRelational Notation to E/R • Translate from 3 tables: Table1 (X,Y,Z) Table2 (L,M,N) Table3 (X,L)
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
More Complex M:NRelational Notation to E/R • Translate from 3 tables: Table1 (X,Y,Z) Table2 (L,M,N) Table3 (X,L,P)
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
More Complex M:NE/R to Relational Notation • Translates to 4 tables:Table1 (A,B,C) Table2 (D,E,F)Table3 (H,I,J)Table4 (A,D,H,K)
Sub-Type / Super-TypeE/R to Relational Notation • 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.