Presentation is loading. Please wait.

Presentation is loading. Please wait.

Transforming an ER Model into a Relational Schema  Cs263 Lecture 10.

Similar presentations


Presentation on theme: "Transforming an ER Model into a Relational Schema  Cs263 Lecture 10."— Presentation transcript:

1 Transforming an ER Model into a Relational Schema  Cs263 Lecture 10

2 Transforming an ER Model into a Relational Schema There are a series of steps that are recommended for converting an E/ER model into a relational schema. These steps are not hard and fast rules, but rather a series of pertinent suggestions that the database designer must use wisely.

3 E/ER to Relational Schema Conversion Steps Step 1  For each ‘strong’ entity in the E/ER model, create a base relation with a column for each simple attribute of that entity.  The key attribute for the entity becomes the primary key of the relation.

4 Example – Converting ‘Strong’ Entities Emp EmpNo Salary Comm Hire Date Name Job EmpNoNumber(4) NameVarchar2(10) JobVarchar2(9) SalNumber(7,2) CommNumber(7,2) HireDateDate Emp Primary Key

5 Example – Converting ‘Strong’ Entities Dept DeptNo Location Name DeptNoNumber(2) NameVarchar2(14) LocationVarchar2(13) Dept Primary Key

6 E/ER to Relational Schema Conversion Steps Step 2 For each ‘weak’ entity, create a relation consisting of all the simple attributes of that entity and also include columns for the primary keys of those entities on whose existence it is dependent.

7 Example – Converting ‘Weak’ Entities Loan LoanNoChar(8) PaymentNoNumber(4)Date AmountNumber(9,2) Payment Composite Primary Key Payment Date Amount Loan No Payment No Discriminator

8 E/ER to Relational Schema Conversion Steps Step 3 When two entities participate in a one-to- many (1-M) relationship, the relation representing the entity with the M (Many) cardinality must have a foreign key column representing this relationship.

9 Example – Converting (1-M) Relationships Dept D# Emp Works in Assigned E# EmpNoNumber(4) NameVarchar2(10) JobVarchar2(9) SalNumber(7,2) CommNumber(7,2) HireDateDate DeptNoNumber(2) Emp Foreign Key As an Employee ‘must’ work in a department, then the DeptNo column in the Emp relation (table) cannot be NULL!

10 Example – Converting (1-M) Relationships EmpNoNumber(4) NameVarchar2(10) JobVarchar2(9) SalNumber(7,2) CommNumber(7,2) HireDateDate DeptNoNumber(2) Emp Foreign Key As an Employee ‘may not’ work in a department, then the DeptNo column in the Emp relation (table) can be NULL! Dept D# Emp Works in Assigned E#

11 E/ER to Relational Schema Conversion Steps Step 4 When two entities participate in a (1-1) relationship, a foreign key column must be included in the relation that represents one of these entities.

12 Example – Converting (1-1) Relationships Emp E# ID Card Belongs to Has ID# EmpNoNumber(6) NameVarchar2(10) Address Varchar2(200 ) DOBDate IDNoChar(10) Emp Foreign Key IDNoChar(10) IssuedDate ExpiresDate EmpNoNumber(6) ID Card Foreign Key EITHER ONE IS ACCEPTABLE

13 E/ER to Relational Schema Conversion Steps Step 5 When two entities participate in a many-to- many (M-M) relationship, then a relation must be created consisting of foreign keys for the two relations that represent the participating entities.

14 Example – Converting (M-N) Relationships Person P# Car Driven by Drives C# PersonNoNumber(6) CarNoChar(7) Person-Car Foreign Key Person P# Car C# Person-Car P#,C#

15 E/ER to Relational Schema Conversion Steps Step 6 Where an entity has a multi-valued attribute, create a relation with a column as a foreign key to the relation that represents the entity and a column for the multi-valued attribute.

16 Language Example – Multi-valued Attributes Programmer EmpNo Language Name EmpNoNumber(2) NameVarchar2(14) Programmer Primary Key EmpNoNumber(2) LanguageVarchar2(20) Prog-Lang Composite Primary Key

17 E/ER to Relational Schema Conversion Steps Step 7 When more than two entities participate in a relationship, then a relation must be created consisting of foreign keys to those relations representing the entities participating in the relationship.

18 Example – Converting Ternary Relationships Match Match No Player Player No Offence Offence No Booking MatchNo Number(4) PlayerNo Number(6) OffenceNo Number(3) Time Date Booking Composite Primary Key

19 E/ER to Relational Schema Conversion Steps Step 8 – Option A For sub-typing, create separate relations for each subtype consisting of those attributes which are peculiar to the given subtype, and include a foreign key to the super-type, that will act as the sub-type’s primary key. Create a separate relation for the super- type!

20 Example – Converting Sub-types EmployeeN o Name Address Employee EMPLOYEE Employee No Name Address SECRETARY Typing Speed TECHNICIAN Grade ENGINEER Type EmployeeN o TypingSpee d Secretary EmployeeN o Grade Technician EmployeeN o Type Engineer

21 E/ER to Relational Schema Conversion Steps Step 8 – Option B For sub-typing, create separate relations for each subtype consisting of all the attributes of the super-type, and all those which are peculiar to the given subtype. The primary key of the super-type becomes the primary key of each sub-type. Do not create a relation for the super-type!

22 Example – Converting Sub-types VehicleNo LicenceNo Price NoOfSeats Car VEHICLE Vehicle No Licence No Price CAR No of Seats TRUCK No of Axles Tonnage Truck VehicleNo LicenceNo Price NoOfAxles Tonnage


Download ppt "Transforming an ER Model into a Relational Schema  Cs263 Lecture 10."

Similar presentations


Ads by Google