Transforming Conceptual Designs into Logical Database Schemas with SQL DDL
ER-to-Relational Mapping is the systematic process of transforming a conceptual ER (or EER) diagram into a logical relational database schema that can be implemented in a DBMS.
Steps 1-7: Map ER Model components
Steps 8-9: Map EER Model constructs
For each regular entity type E in the ER schema:
ER Entity: EMPLOYEE with attributes {SSN, Name, BDate, Address}
Relational Schema:
SSN is chosen as the primary key (underlined)
For composite attributes, include only the simple component attributes. For example, if Name is composite (Fname, Minit, Lname), include Fname, Minit, and Lname as separate attributes.
For each weak entity type W with owner entity type E:
Weak Entity: DEPENDENT (partial key: Dependent_name)
Owner Entity: EMPLOYEE (primary key: SSN)
Relational Schema:
Primary key is {ESSN, Dependent_name}
The owner's primary key becomes both a foreign key AND part of the primary key of the weak entity relation.
For each binary 1:1 relationship type R between S and T:
Choose one relation (preferably with total participation) and include the other's primary key as a foreign key.
Example: EMPLOYEE MANAGES DEPARTMENT (1:1)
Mgr_ssn is the foreign key in DEPARTMENT
If both entities have total participation, merge them into a single relation with attributes from both.
Create a separate relation for the relationship with foreign keys to both entities. (Rarely used for 1:1)
Use Foreign Key approach when one side has total participation. Place the foreign key in the relation with total participation to avoid NULL values.
For each binary 1:N relationship type R:
Relationship: EMPLOYEE (N) WORKS_FOR (1) DEPARTMENT
Relational Schema:
DNO is foreign key in EMPLOYEE (the N-side)
The foreign key always goes in the relation on the N-side (many side) of the relationship.
You could create a separate relationship relation, but this is rarely done for 1:N relationships as it creates unnecessary complexity and has little benefit.
For each binary M:N relationship type R:
Relationship: EMPLOYEE (M) WORKS_ON (N) PROJECT
Relational Schema:
Primary key is {ESSN, PNO}
Hours is an attribute of the relationship
M:N relationships always require a separate relationship relation. You cannot use foreign keys in either participating entity relation because that would violate the relational model (multivalued attributes).
For each multivalued attribute A:
Multivalued Attribute: LOCATIONS of DEPARTMENT
Relational Schema:
Primary key is {Dnumber, Dlocation}
The relational model requires atomic values (First Normal Form). Multivalued attributes violate this, so they must be stored in a separate relation.
For each n-ary relationship type R (where n > 2):
Relationship: SUPPLIER supplies PART to PROJECT
Relational Schema:
Primary key is {Sname, Part_no, Proj_name}
If the relationship has cardinality constraints (e.g., M:N:1), the primary key may be just the combination of the foreign keys on the M and N sides, not all foreign keys.
For specialization/generalization hierarchies, choose from:
Create a relation for the superclass and separate relations for each subclass.
Create relations only for subclasses, each containing all inherited + specific attributes.
Create a single relation with all attributes from superclass and all subclasses.
Single relation with multiple Boolean type attributes (one per subclass).
For each category (union type):
Category: OWNER (union of PERSON, BANK, COMPANY)
Relational Schema:
Owner_id is the surrogate key linking to specific superclass
Categories have superclasses with different key attributes. A surrogate key provides a uniform way to reference category members regardless of which superclass they belong to.
Data Definition Language (DDL) is used to define, modify, and delete database structures. Key DDL commands: CREATE, ALTER, DROP.
Attribute Constraints:
Foreign Key Conditions:
With ER-to-Relational mapping complete, you can now: