2) E-R Model To Relational Model
2) E-R Model To Relational Model
Students
mn name age email
E-R Model to Relational Model
• Weak entity set E translates to table E
• A weak entity can be identified uniquely only by
considering the primary key of another (owner)
entity.
• – Owner entity set and weak entity set must
participate in a one-to-many relationship set (1
owner, many weak entities).
• – When the owner entity is deleted, all owned
weak entities must also be deleted.
E-R Model to Relational Model
• Weak entity set E translates to table E
• CREATE TABLE Policy (
• pname CHAR(20),
• age INTEGER,
• cost NUMBER(10,2),
• ssn CHAR(11),
• PRIMARY KEY (pname, ssn),
• FOREIGN KEY (ssn) REFERENCES Employees,
• ON DELETE CASCADE)
Policy
pname age cost ssn
E-R Model to Relational Model
• Relationship Sets to Tables
• Columns of table R should include
• Attributes of the relationship set
• Primary key attributes of each component entity
set
E-R Model to Relational Model
• Relationship Sets (without Constraints) to Tables
• Create a table for the relationship set.
• Add all primary keys of the participating entity
sets as fields of the table.
• Add fields of attribute in the relationship.
• Declare a primary key using all key fields from
the entity sets.
• Declare foreign key constraints for all these
fields from the entity sets.
E-R Model to Relational Model
• Relationship Sets (without Constraints) to Tables
Students Courses
mn name age email code name year
Takes
mn code mark
E-R Model to Relational Model
• Relationship Sets (without Constraints) to Tables
Students
Mn name age email
Courses
code name year
Takes
mn code mark
E-R Model to Relational Model
• Relationship Sets (with Constraints) to Tables
• Create a table for the relationship set.
• Add all primary keys of the participating entity sets as
fields of the table.
• Add a field for each attribute of the relationship.
• Declare a primary key using the key fields from the
source entity set only.
• Declare foreign key constraints for all the fields from
the source and target entity sets.
E-R Model to Relational Model
• Relationship Sets (with Constraints) to Tables
Students
DoS
mn name email Staff id
Directed By
mn Staff id
E-R Model to Relational Model
• Relationship Sets (with Constraints) to Tables