Skip to content
GATEiit

GATE CSE · Databases

ER model

Entity-relationship modelling: entities, attribute kinds, relationships with cardinality and participation, weak entities, specialisation and aggregation, and the rules for mapping an ER diagram to the minimum number of tables.

Before you start

This topic comes before: Relational model: relational algebra, tuple calculus and SQL

Concept notes

1. Entities and attributes

An entity is a distinguishable real-world object (a student, a course); an entity set is a collection of similar entities, drawn as a rectangle. Properties are attributes, drawn as ellipses.

Attribute kind Meaning Notation In tables
Simple cannot be divided ellipse one column
Composite made of parts, e.g. name(first, last) ellipse with child ellipses one column per part
Multivalued several values per entity, e.g. phone double ellipse a separate table
Derived computed from others, e.g. age from date of birth dashed ellipse usually not stored
Key uniquely identifies an entity underlined name primary key

A key of an entity set is a minimal set of attributes whose values differ for every pair of entities. An attribute may also be null (unknown or not applicable) unless it is part of the key.

The domain (value set) of an attribute is the set of values it may take. For a composite attribute, only the leaf parts become columns.

StudentEnrollsCourserollnamegradecidtitlephonecreditsMNdouble line = total participation; double ellipse = multivalued
Student (key roll, multivalued phone) enrolls in Course (key cid); grade is an attribute of the relationship

2. Relationships: degree, cardinality and participation

A relationship set (a diamond) associates entities from entity sets; formally it is a subset of E1×E2×⋯×En. Its degree is n: binary (2) is most common; ternary (3) relates three sets at once. A recursive relationship relates an entity set to itself with roles, e.g. Employee manages Employee. A relationship may have its own attributes (grade of an enrolment).

Cardinality ratio of a binary relationship between A and B:

  • 1:1: each A with at most one B and each B with at most one A.
  • 1:N: each A with many B, each B with at most one A.
  • M:N: no limit on either side.

Participation: total (every entity must take part, drawn as a double line) or partial (single line). Total participation is an existence constraint, a minimum of 1.

Counting instances. If A–B is 1:N (one A, many B), each B appears in at most one pair, so the relationship has at most ∣B∣ instances. For 1:1, at most min⁡(∣A∣,∣B∣); for M:N, at most ∣A∣⋅∣B∣. Partial participation allows 0.

(min, max) notation writes a pair on each line, e.g. (1, 1) or (0, N): the entity takes part in at least min and at most max relationship instances. Placement conventions differ between books, so read the question's legend.

3. Weak entity sets

A weak entity set has no key of its own; its entities are identified only together with an owner (identifying) entity. Example: rooms numbered 101, 102 exist in many buildings, so room_no alone is not unique.

  • Drawn as a double rectangle; its identifying relationship is a double diamond.
  • Its participation in the identifying relationship is total (every room belongs to a building), and the relationship is many-to-one from weak to owner.
  • The partial key (discriminator), drawn with a dashed underline, distinguishes weak entities of the same owner.
  • Key of the weak entity set = owner's primary key + partial key, e.g. (bno, room_no).

When mapped to tables, the weak entity gets its own table containing the owner's key as a foreign key (usually with ON DELETE CASCADE), and the identifying relationship needs no separate table.

A weak entity set can itself own another weak entity set; then the key chains, e.g. (bno, room_no, seat_no).

BuildingHasRoom1Nbnoroom_noareaRoom key = (bno, room_no); room_no is the partial key (dashed underline)
Weak entity Room, identified through Building by the identifying relationship Has

4. Mapping an ER diagram to tables

ER element Tables produced Primary key
Strong entity one table, simple and composite leaf attributes its key
Weak entity one table with owner's key added owner key + partial key
Multivalued attribute separate table (entity key, value) both columns
M:N relationship separate table: both keys + relationship attributes key of A + key of B
1:N relationship no new table: put A's key as a foreign key in B (the N side) key of B
1:1 relationship no new table: foreign key on one side, preferably the side with total participation key of either
1:1 with total participation on both sides the two entities can be merged into one table key of either
n-ary relationship (n ≥ 3) separate table keys of the "many" sides

Minimum number of tables: count strong and weak entities, add one per M:N (and n-ary) relationship and one per multivalued attribute, and subtract one for each 1:1 with total participation on both sides that you merge. 1:N and other 1:1 relationships add nothing.

Key of a relationship table (if it is kept as a table): M:N gives (key A, key B); 1:N gives key of the N side alone; 1:1 gives the key of either side.

5. Specialisation, generalisation and aggregation

Specialisation splits an entity set into sub-classes (top down): Employee into Engineer and Manager. Generalisation is the same structure built bottom up: Car and Truck into Vehicle. Both form an ISA hierarchy; sub-classes inherit all attributes and relationships of the super-class.

Constraints on an ISA hierarchy:

  • Disjoint vs overlapping: can an entity belong to more than one sub-class?
  • Total vs partial: must every super-class entity belong to some sub-class?

Mapping options: (1) one table for the super-class and one per sub-class holding the key plus its own attributes; (2) only sub-class tables, each with all inherited attributes (works only when the specialisation is total, and duplicates data if it overlaps); (3) one table with all attributes and a type column (many nulls).

Aggregation treats a relationship (with its entities) as a higher-level entity, so that it can take part in another relationship. Example: the relationship works-on between Employee and Project is aggregated and then related to Machine by uses. This avoids a ternary relationship when the second relationship applies only to existing (employee, project) pairs.

Formulas to remember

Max instances of a 1:N relationshipB is the N side
∣R∣≤∣B∣
Max instances of a 1:1 relationship
∣R∣≤min⁡(∣A∣,∣B∣)
Max instances of an M:N relationship
∣R∣≤∣A∣⋅∣B∣
Weak entity key
key(W)=key(owner)∪partial key(W)

Common mistakes

  • Creating a separate table for every relationship; only M:N and n-ary relationships need one in the minimum count.
  • Merging the two entities of a 1:1 relationship when participation is not total on both sides.
  • Putting the foreign key on the 1 side of a 1:N relationship; it goes in the N side's table.
  • Storing a multivalued attribute as repeated columns instead of a separate table.
  • Taking the partial key alone as the key of a weak entity set; the owner's key must be added.
  • Counting a composite attribute as one column; each leaf part is a column.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Minimum number of tables

numerical

Strong entity sets A, B, C, D. A has one multivalued attribute. R1 relates A and B (M:N). R2 relates B and C (1:N, one B to many C). R3 relates C and D (1:1, total participation on both sides). Find the minimum number of tables.

  1. Step 1: Start with one table per entity set.

    Try it on paper first.

Example 2: Keys of relationship tables

conceptual

Student(roll) and Course(cid) are linked by a relationship Takes with attribute grade. If Takes were kept as a table Takes(roll, cid, grade), what is its key when Takes is (a) M:N, (b) many students to one course (N:1), (c) 1:1?

  1. Step 1: M:N: can a roll repeat? can a cid repeat?

    Try it on paper first.

Example 3: Mapping a weak entity

conceptual

Building(bno, address) owns weak entity Room(room_no, area) through identifying relationship Has. Write the tables.

  1. Step 1: Map the owner.

    Try it on paper first.

Example 4: Reading cardinality and participation from a description

conceptual

Every student must enrol in at least one course; a course may have no students; a student may take many courses and a course may have many students. Describe Enrolls.

  1. Step 1: Find the cardinality ratio.

    Try it on paper first.

Previous year questions

5 official GATE CSE questions on this topic, newest first.

Practise these 5 PYQs →

Topic test

10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.