Courses / Databases for Backend Interviews / Chapter 5
Module 3 · Data modelling and the ER model · Chapter 5 of 27
The Entity-Relationship Model: Entities, Relationships, Cardinality and Mapping
Builds on Data Modelling: From Requirements to Conceptual, Logical and Physical Models. Next up: The Relational Model: Relations, Keys, Integrity and Relational Algebra.
Part 1 · Entities and attributes
Entities, entity sets and attributes
A public library network has branches, members, books and loans. The entity-relationship model describes that world as things and the connections between them, before any table exists.
An entity is one distinct thing the business keeps facts about: the member Anita Bose, or the book River Atlas. An entity set is the collection of all entities of one kind, such as all members. People say "entity" for both and the context tells which. In tables, an entity set becomes a table and an entity becomes a row.
An attribute is a fact about an entity: a name, a joining date, a city. Each attribute draws its values from a domain, the set of allowed values, such as "dates" or "text up to 100 characters". In tables, attributes become columns.
A key attribute is one whose values tell entities apart. A set of attributes that identifies an entity is a superkey. A superkey with no unnecessary attribute is a candidate key. The one you pick to identify entities is the primary key. A member id is a typical choice. The next chapter defines these with more care.