130 likes | 204 Views
Transforming Entity-Relationship Models Into Relational Database Implementations. Two Simple Rules for Transforming an ERD into Tables. Every entity will be a table. A relationship will be a table only if: It is a many to many relationship or It has its own attributes.
E N D
Transforming Entity-Relationship Models Into Relational Database Implementations
Two Simple Rules forTransforming an ERD into Tables • Every entity will be a table. • A relationship will be a table only if: • It is a many to manyrelationship • or • It has its own attributes.
Placement of Foreign KeysIn a Transformation One to Many: The primary key from “One” table is used as the foreign key in the “Many” table. One to One: Theprimary key from one of the “One” table is used as the foreign key in the other “One” table. Many to Many: The relationship becomes a “bridge” table and the primary key from each of the “Many” tables is used as a foreign key. All of the foreign keys collectively become the composite primary key of the new linking table.
Binary One to Many PUBLISHER ( Pnum, Name, Addr ) BOOK ( ISBN, Title, Edition, Pnum )
Binary One to One STATE ( Code, Name, Size ) GOVERNOR ( SSN, Name, BDate, Code ) or STATE ( Code, Name, Size , SSN ) GOVERNOR ( SSN, Name, BDate )
Binary Many to Many STUDENT ( Snum, Name, Addr ) COURSE ( Cnum, CTitle, CrHrs ) TAKES ( Snum, Cnum, Term )
Unary One to One EMPLOYEE ( Enum, Name, SpouseEnum )
Unary One to Many EMPLOYEE ( Enum, Name, MgrEnum )
Unary Many to Many PART ( Pnum, Name ) ASSEMBLY ( Anum, Pnum )
Ternary PART ( Pnum, Pname ) SUPPLIER ( Snum, SName) WAREHOUSE ( Wnum, City ) SHIPSTO ( Pnum, Snum, WNum )
Composite Entity STUDENT ( Snum, Name, Addr ) COURSE ( Cnum, CTitle, CrHrs ) TAKES ( Enum, Snum, Cnum, Term )
Supertype-Subtype STUDENT ( PID, Major ) GRADUATE ( PID, Thesis ) UNDERGRADUATE ( PID, Hours )