Using the Entity Relationship Model
In this section, we’ll look at the steps required to manually
translate an ER model into database tables. We’ll then perform these
steps using the music database as
an example. In Using Tools for Database Design,” we’ll see how
we can automate this process with the MySQL Workbench tool.
Mapping Entities and Relationships to Database Tables
When converting an ER model to a database schema, we work through each entity and then through each relationship according to the following rules to end up with a set of database tables.
Map the entities to database tables
For each strong entity, create a table comprising its attributes and designate the primary key. The parts of any composite attributes are also included here.
For each weak entity, create a table comprising its attributes and including the primary key of its owning entity. The primary key of the owning entity is known as a foreign key here, because it’s a key not of this table, but of another table. The primary key of the table for the weak entity is the combination of the foreign key and the partial key of the weak entity. If the relationship with the owning entity has any attributes, add them to this table.
For each multivalued attribute of an entity, create a table comprising the entity’s primary key and the attribute.
Map the relationships to database tables
For each one-to-one relationship between two entities, include the primary key of one entity as a foreign key in the table belonging to the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access