Skills101

DBMS & SQL · Lesson 2 of 13 · Updated ·

ER Model — Entities, Attributes, Relationships and Cardinality

Before creating tables, designers draw an Entity–Relationship (ER) diagram: a picture of what things the system stores and how they connect.

ER diagram: entity Student (attributes roll_no as key, name, email) connected through the relationship "enrolls" to entity Course (attributes code as key, title), many-to-many

1. The building blocks

SymbolNameExample
RectangleEntity — a thing we store data aboutStudent, Course
EllipseAttribute — a propertyname, email
Underlined ellipseKey attribute — identifies the entityroll_no
DiamondRelationship — how entities connectenrolls, teaches

2. Types of attributes

  • Simple — can't be divided: age.
  • Composite — made of parts: name → first, last; address → street, city, PIN.
  • Multi-valued — many values: phone_numbers (double ellipse).
  • Derived — calculated from others: age from date_of_birth (dashed ellipse).
  • Key — unique identifier: roll_no.

3. Cardinality: how many?

TypeMeaningExample
1 : 1one A with one BPerson — Aadhaar card
1 : None A with many BDepartment — Employees
M : Nmany A with many BStudents — Courses

Participation: if every employee must belong to a department, Employee has total participation (double line); if not every course must have students, Course has partial participation.

4. Weak entities

A weak entity can't be identified on its own — it depends on a strong entity. Example: Dependent (an employee's child) is identified by the employee's id + the dependent's name. Drawn with a double rectangle.

5. From ER diagram to tables

ER partBecomes
Strong entitya table; key attribute → primary key
1 : N relationshipput the "one" side's key as a foreign key in the "many" side table
M : N relationshipa new table with both keys (a junction table)
Multi-valued attributea separate table

For the picture above:

  • students(roll_no PK, name, email)
  • courses(code PK, title)
  • enrollments(roll_no FK, code FK, PRIMARY KEY(roll_no, code)) ← the M : N relationship

6. Extended ER: generalisation and specialisation

  • Specialisation (top-down): Employee → Developer, Manager.
  • Generalisation (bottom-up): Car + Bike → Vehicle.
  • Aggregation: treat a relationship as an entity (a "project assignment" that itself is monitored by a manager).

Common mistakes

  • Putting a foreign key on the wrong side of a 1 : N relationship (it goes on the many side).
  • Trying to store an M : N relationship with a foreign key in one table — you need a junction table.
  • Storing derived attributes (age) instead of the base value (date of birth).

Quick recap

  • Entity (rectangle), attribute (ellipse), key (underlined), relationship (diamond).
  • Attribute types: simple, composite, multi-valued, derived, key.
  • Cardinality 1:1, 1:N, M:N; total vs partial participation.
  • M:N → junction table; 1:N → foreign key on the many side.

Practice what you learned

📝 Quiz: ER Model5 questions · instant answers & explanations · +10 XP · counts towards your free certificateTake the quiz →