Skip to main content

Databases (DBMS)

ER Model

Start Databases here: learn to read an ER diagram, decide cardinality and participation, handle weak entities, and convert any diagram into the minimum number of relational tables.

~3 hrs ~0.5–1 marks · Moderate 8 samples · 8 practice · 8 cards

GATE CSE ER model — entities, attributes, relationships, keys, cardinality (1:1, 1:N, M:N), participation, weak entities, specialization and ER-to-relational mapping with minimum-table counts, sample questions, flashcards and drills.

Learning outcomes

  • Classify attributes as simple, composite, multivalued, derived or key
  • State cardinality and participation constraints from an ER diagram
  • Identify weak entities, discriminators and the weak-entity primary key
  • Map entities, relationships and multivalued attributes to the minimum number of tables

Entities, attributes, relationships and keys

  • An ENTITY is a distinguishable real-world object (a student, a course). An ENTITY SET is a collection of entities of the same type; it is drawn as a rectangle. Each entity is described by ATTRIBUTES (ellipses).
  • Attribute kinds: SIMPLE (atomic) vs COMPOSITE (name = first + last); SINGLE-VALUED vs MULTIVALUED (phone numbers; double ellipse); STORED vs DERIVED (age from date of birth; dashed ellipse); KEY attribute (underlined) uniquely identifies an entity in its set.
  • A RELATIONSHIP associates two or more entities; a RELATIONSHIP SET is drawn as a diamond. The DEGREE is the number of participating entity sets: binary (2), ternary (3). A relationship may have its own descriptive attributes (for example enrolled_on).
  • A relationship in which one entity set participates twice with different ROLES is recursive (unary), for example Employee supervises Employee.
  • KEYS: a super key identifies an entity; a candidate key is a minimal super key; one candidate key is chosen as the primary key. The key of a relationship set is formed from the keys of the participating entity sets (and depends on cardinality).
  • ER diagrams are conceptual design; they are later translated into relational tables. Redundant derived attributes are not stored in the table in a good design.
SymbolMeaning
Rectanglestrong entity set
Double rectangleweak entity set
Diamondrelationship set
Double diamondidentifying relationship of a weak entity
Ellipse / double ellipse / dashed ellipseattribute / multivalued attribute / derived attribute
Single line / double linepartial participation / total participation

Worked example

Problem. In Student(roll, name, dob, age, phones) which attribute can be derived, which is multivalued and which is the likely key?

Solution. age is derived (from dob), phones is multivalued (a student may have several numbers), roll is the key attribute. name may be composite (first, last).

Cardinality and participation constraints

  • CARDINALITY RATIO of a binary relationship R between A and B: ONE-TO-ONE (1:1), ONE-TO-MANY (1:N), MANY-TO-ONE (N:1) or MANY-TO-MANY (M:N). In 1:N from A to B, one A entity relates to many B entities but each B entity relates to at most one A entity.
  • PARTICIPATION: TOTAL (every entity of the set must take part; double line) or PARTIAL (some entities may not take part; single line). Total participation is also called existence dependency.
  • STRUCTURAL CONSTRAINT (min, max) on each edge combines both ideas: (0,N) partial many, (1,1) total one, and so on. Check which side the N is on before deciding where the foreign key goes.
  • A 1:1 relationship with total participation on one side is the natural candidate for merging the two entity sets into one table (or placing the key of the other side as a foreign key).
  • For counting relationships: with n entities in A and m in B, the number of possible binary relationship instances is at most n * m (M:N), at most max(n, m) pairs in 1:1, and at most the size of the many-side in 1:N.
  • KEY OF A RELATIONSHIP SET depends on cardinality: M:N uses the union of both entity keys; 1:N (or N:1) uses only the key of the MANY side; 1:1 can use either entity key. This is why a 1:N relationship folds into the many-side table without needing a new key.
  • Reading (min, max) pairs: (0,1) = optional and at most one, (1,1) = exactly one (total, functional), (0,N) = optional many, (1,N) = at least one. A foreign key that comes from a (1,1) edge is declared NOT NULL; from a (0,1) edge it may be NULL.
  • A binary relationship that is 1:N from A to B can never be turned into M:N by participation constraints alone: participation says whether an entity MUST take part, cardinality says HOW MANY partners it can have. GATE often swaps these two on purpose.
  • Descriptive attributes of a 1:N or 1:1 relationship move with the foreign key into the table that holds it; descriptive attributes of an M:N relationship stay in the relationship table.

Formulas to remember

  • M:N between A and B: maximum relationship instances = |A| * |B|
  • 1:1 between A and B: maximum relationship instances = min(|A|, |B|)
  • 1:N from A to B (each B at most one A): maximum relationship instances = |B|
CardinalityKey of relationship setMax instances (|A| = n, |B| = m)Typical mapping
1:1key of A or key of Bmin(n, m)FK in either table, or merge
1:N (A one, B many)key of Bmkey of A as FK in B
N:1 (A many, B one)key of Ankey of B as FK in A
M:Nkey of A + key of Bn * mseparate relationship table

Worked example

Problem. Each department has many employees; each employee works in exactly one department. Give the cardinality and the participation of Employee.

Solution. Department to Employee is 1:N (Employee to Department is N:1). Every employee works in exactly one department, so Employee participates totally in works_in (min = 1, max = 1).

Three mapping diagrams between entity sets A and B showing one-to-one, one-to-many and many-to-many relationship instances with the table mapping rule for each.
Cardinality ratios: draw the instances as lines between dots to see 1:1, 1:N and M:N, and read off the maximum number of instances and the mapping rule.

Weak entities, specialization and ER to relational mapping

  • A WEAK ENTITY SET has no key of its own; it is identified by the key of an OWNER (identifying, strong) entity set together with its own DISCRIMINATOR (partial key, dashed underline). It participates totally in an identifying relationship (double diamond) that is 1:N from owner to weak.
  • PRIMARY KEY OF A WEAK ENTITY TABLE = key of owner + discriminator. The owner key is also a foreign key, normally with ON DELETE CASCADE.
  • SPECIALIZATION (top-down) / GENERALIZATION (bottom-up) gives IS-A hierarchies with inheritance. Constraints: disjoint vs overlapping, total vs partial. AGGREGATION treats a relationship as an entity so that it can take part in another relationship.
  • MAPPING RULES: (1) strong entity -> one table with its simple attributes (composite flattened) and primary key. (2) weak entity -> table with owner key + discriminator + attributes. (3) multivalued attribute -> separate table (entity key, value) with composite key. (4) M:N relationship -> separate table holding both keys plus relationship attributes. (5) 1:N relationship -> add the key of the ONE side as a foreign key to the table of the N side (no new table). (6) 1:1 relationship -> merge into one of the tables (prefer the total side) by a foreign key or merge both. (7) derived attributes -> not stored.
  • MINIMUM NUMBER OF TABLES: count one table per entity set, add one extra table per M:N relationship and per multivalued attribute, and add none for 1:N and 1:1 (they merge into the existing tables). Merge both sides of a 1:1 relationship with total participation on both ends to get one table.
  • A ternary relationship is converted to a table that contains the keys of all three participants; the primary key depends on cardinality (for M:N:N all three keys together).
  • Specialization mapping options: one table per entity (super + sub with shared key), one table per subclass only (total, disjoint), or one single table with a type attribute; GATE usually asks the number of tables for the simple options.
ER constructRelational mappingExtra table?
Strong entity setone table, primary key = key attributeyes (its own)
Weak entity settable with owner key + discriminator as keyyes (its own)
Multivalued attributetable(owner key, value)yes
M:N relationshiptable(key of A, key of B, attrs)yes
1:N relationshipforeign key (one-side key) in N-side tableno
1:1 relationshipforeign key in either table or mergeno

Worked example

Problem. E1(a1, a2), E2(b1, b2), E3(c1, c2) with keys a1, b1, c1. R1 is 1:N between E1 and E2 (N at E2); R2 is M:N between E2 and E3. Find the minimum number of tables.

Solution. Three entity tables E1, E2, E3 are needed. R1 (1:N) merges into E2 by adding a1 as a foreign key (no table). R2 (M:N) needs its own table (b1, c1). Total = 3 + 1 = 4 tables.

ER diagram of Employee owning a weak entity Dependent through a double-diamond identifying relationship, with the relational tables and the composite primary key (eid, dname).
Weak entity: Dependent has no key of its own, so its table key is the owner key eid plus the discriminator dname, and eid is a foreign key with ON DELETE CASCADE.

Counting tables: the full ER-to-relational checklist

  • STEP 1: one table per strong entity set and per weak entity set. STEP 2: one extra table per multivalued attribute. STEP 3: one extra table per M:N (or higher-degree) relationship. STEP 4: add NOTHING for 1:N and 1:1 relationships, but add foreign key columns. STEP 5: merge tables only when a 1:1 relationship allows it and the question asks for the MINIMUM.
  • MERGE RULES FOR 1:1: if the participation of BOTH sets is total, merge the two entity sets into ONE table. If only one side is total, put the foreign key on the total side (no merge needed); if neither side is total, an extra relationship table avoids NULLs, but the minimum-table answer still uses a foreign key.
  • A TERNARY relationship becomes one table holding the three entity keys and the descriptive attributes. A relationship with an arrow (functional) on one participant can instead be merged into that participant’s table.
  • WEAK ENTITY with a 1:N identifying relationship needs ONE table (the identifying relationship is absorbed into it). A weak entity that also has a multivalued attribute needs a further table.
  • RECURSIVE relationships: 1:N recursive (employee-manager) adds a foreign key column to the same table; M:N recursive (course-prerequisite) needs a table with two columns that both reference the same entity key under different role names.
  • GENERALIZATION counts: for a superclass with k subclasses, "one table per entity" gives k + 1 tables, "one table per subclass" gives k tables (only for total, disjoint specialization), and a single table with a type attribute gives 1 table.
  • Number of FOREIGN KEY columns is not asked often, but remember that each 1:N relationship adds one FK set to the N-side table, and a relationship table adds one FK set per participating entity.

Formulas to remember

  • Minimum tables = (entity sets) + (M:N relationships) + (multivalued attributes) - (1:1 merges)
  • Specialization with k subclasses: k + 1 (one per entity), k (subclass only), 1 (single table)
SituationTablesReason
E1 - E2 is 1:1, total on both sides1merge both entity sets into one table
E1 - E2 is 1:1, total on E1 only2FK of E2 key in E1; no merge needed
Weak entity W (1:N identifying) owned by E2E table + W table; no table for the relationship
Entity with one multivalued attribute2entity table + (key, value) table
Ternary M:N:N among E1, E2, E34three entity tables + one relationship table

Worked example

Problem. Student(sid, name, {phone}), Course(cid, title) and Dept(did, dname). Dept to Student is 1:N (each student belongs to exactly one department). Student to Course is M:N with attribute grade. Find the minimum number of tables and give the schemas.

Solution. Entity tables: Student, Course, Dept = 3. Multivalued phone: +1 = StudentPhone(sid, phone). M:N Enrolls: +1 = Enrolls(sid, cid, grade). The 1:N relationship adds nothing: did becomes a foreign key in Student(sid, name, did). Total = 3 + 1 + 1 = 5 tables: Dept(did, dname), Student(sid, name, did), StudentPhone(sid, phone), Course(cid, title), Enrolls(sid, cid, grade).

Entity sets E1, E2, E3 with a 1:N relationship R1 and an M:N relationship R2 mapped to four tables, with a table of mapping rules showing which constructs need their own table.
Counting rule in one picture: three entities plus the M:N relationship give 4 tables; the 1:N relationship only adds a foreign key to E2.

Worked ER examples: weak entity, ternary and 1:1

  • Always identify first: (a) which sets are weak (double rectangle), (b) which relationships are M:N or ternary, (c) which attributes are multivalued, (d) which 1:1 relationships have total participation on both sides. Only then count tables.
  • A common trap is to treat a weak entity’s identifying relationship as a separate table. It is not: the weak table already contains the owner key, so the relationship is folded in.
  • Another trap is to count a 1:1 relationship with total participation on only ONE side as mergeable. It is mergeable only if you accept the NULLs; the standard minimum puts the FK on the total side and keeps two tables.

Worked example

Problem. Employee(eid, name, {skill}) owns a weak entity Dependent(dname, age) via an identifying 1:N relationship. Employee also has a 1:1 relationship Manages with Project(pid, title); both sets have total participation. Supplier(sid), Part(pno) and Project take part in a ternary relationship Supplies(qty) with M:N:N. How many tables are needed at minimum?

Solution. Employee: 1. Skill (multivalued): +1 = EmpSkill(eid, skill). Dependent (weak, key eid + dname): +1 (identifying relationship adds nothing). Project: 1, but Manages is 1:1 total on both sides, so Employee and Project merge into ONE table (eid, name, pid, title); remove the separate Project count. Supplier: +1. Part: +1. Ternary Supplies: +1 = Supplies(sid, pno, pid, qty), key (sid, pno, pid). Count: Employee+Project (merged) 1, EmpSkill 1, Dependent 1, Supplier 1, Part 1, Supplies 1 = 6 tables.

Exam tips

  • The foreign key of a 1:N relationship always goes on the N side (the "many" side).
  • Count tables: entities + M:N relationships + multivalued attributes; 1:N and 1:1 add nothing.
  • Weak entity key = owner key + discriminator; it must have total participation in its identifying relationship.
  • A double line means total participation; a double diamond means identifying relationship.
  • Derived attributes are not stored; composite attributes are flattened into component columns.
Exam pattern · 8 questions

GATE sample questions & answers

8 GATE-style MCQs for ER Model with full explanations. Attempt each question before revealing the answer.

Q1 Classic GATE ER mapping

Entity sets A(a1, a2) and B(b1, b2) have keys a1 and b1. A has an M:N relationship R with B that carries an attribute r1. What is the minimum number of tables required?

  • A) 1
  • B) 2
  • C) 3
  • D) 4
Show answer & explanation

Answer: C

A and B each need a table, and an M:N relationship needs its own table (a1, b1, r1). Minimum = 3.

Q2

Department and Employee have a 1:N relationship (one department, many employees) and Employee participates totally. The minimum number of tables is:

  • A) 1
  • B) 2
  • C) 3
  • D) 4
Show answer & explanation

Answer: B

Two entity tables suffice: the department key is added to Employee as a foreign key. The 1:N relationship needs no extra table.

Q3

The primary key of a weak entity set is formed by:

  • A) its discriminator alone
  • B) the key of the owner entity alone
  • C) the key of the owner entity together with its discriminator
  • D) all of its attributes always
Show answer & explanation

Answer: C

A weak entity is identified by its owner’s key plus its own partial key (discriminator).

Q4

Person(ssn, name, phone) where phone is multivalued. Mapping to the relational model needs a minimum of how many tables?

  • A) 1
  • B) 2
  • C) 3
  • D) 4
Show answer & explanation

Answer: B

Person(ssn, name) and PersonPhone(ssn, phone). The multivalued attribute is moved to its own table.

Q5

In an ER diagram, a double line connecting an entity set to a relationship set indicates:

  • A) partial participation
  • B) total participation
  • C) a weak entity
  • D) a derived attribute
Show answer & explanation

Answer: B

A double line means every entity of the set must participate in the relationship (total participation).

Q6

E1, E2, E3 are strong entity sets. R1 is a 1:N relationship from E1 to E2 and R2 is an M:N relationship between E2 and E3. The minimum number of tables is:

  • A) 3
  • B) 4
  • C) 5
  • D) 6
Show answer & explanation

Answer: B

E1, E2 (with E1’s key as foreign key), E3 and the table for R2 give 4 tables.

Q7

In a 1:N relationship between X (one) and Y (many), the foreign key is placed in:

  • A) X
  • B) Y
  • C) a new table always
  • D) both X and Y
Show answer & explanation

Answer: B

The key of the one side (X) is stored in the many side (Y) as a foreign key.

Q8

A relationship set Supervises between Employee and Employee (a manager supervises many employees, each employee has at most one manager) is mapped to:

  • A) a separate table with two foreign keys
  • B) a foreign key column (manager id) in the Employee table
  • C) two tables
  • D) cannot be represented
Show answer & explanation

Answer: B

It is a recursive 1:N relationship; add the manager’s id as a foreign key column in the Employee table itself.

Topic drill · 8 questions

8 practice questions — ER Model

Extra page-specific practice beyond the GATE samples. Attempt all 8, then reveal answers to check your reasoning.

P1

Employee(eid, name) has a dependent weak entity Dependent(dname, age) related by an identifying 1:N relationship. The primary key of the Dependent table is:

  • A) dname
  • B) eid
  • C) (eid, dname)
  • D) (eid, dname, age)
Show answer & explanation

Answer: C) (eid, dname)

Owner key eid together with the discriminator dname identifies a dependent; age is not needed.

P2

A 1:1 relationship R between E1 and E2 with total participation of both entity sets can be represented with a minimum of how many tables?

  • A) 1
  • B) 2
  • C) 3
  • D) 4
Show answer & explanation

Answer: A) 1

Because both sets participate totally in a 1:1 relationship, they can be merged into a single table.

P3

A ternary M:N:N relationship among three entity sets is mapped to a table whose primary key is:

  • A) any one of the three keys
  • B) the union of the three entity keys
  • C) only the two N-side keys
  • D) a new surrogate key necessarily
Show answer & explanation

Answer: B) the union of the three entity keys

With many-to-many-to-many participation a combination of all three keys is required to identify a relationship instance.

P4

Entity set A has 4 entities and B has 6. In an M:N relationship between A and B, the maximum number of relationship instances is:

  • A) 4
  • B) 6
  • C) 10
  • D) 24
Show answer & explanation

Answer: D) 24

Every A entity can relate to every B entity: 4 * 6 = 24.

P5

In a 1:1 relationship between A (4 entities) and B (6 entities), the maximum number of relationship instances is:

  • A) 4
  • B) 6
  • C) 10
  • D) 24
Show answer & explanation

Answer: A) 4

Each entity takes part in at most one instance, so the maximum is min(4, 6) = 4.

P6

Which of the following is NOT stored as a column in the relational table of an entity?

  • A) simple attribute
  • B) derived attribute
  • C) one component of a composite attribute
  • D) key attribute
Show answer & explanation

Answer: B) derived attribute

Derived attributes are computed from other attributes and are normally not stored.

P7

A weak entity set must participate in its identifying relationship with:

  • A) partial participation
  • B) total participation
  • C) no participation constraint
  • D) either, it does not matter
Show answer & explanation

Answer: B) total participation

A weak entity cannot exist without its owner, so its participation in the identifying relationship is total.

P8

E1, E2, E3 each have a key. E1-E2 is a 1:1 relationship with total participation on both sides, and E2-E3 is a 1:N relationship (N at E3). Merging wherever possible, the minimum number of tables is:

  • A) 1
  • B) 2
  • C) 3
  • D) 4
Show answer & explanation

Answer: B) 2

E1 and E2 merge into one table (1:1, total on both sides). E3 keeps its own table and takes the key of E2 as a foreign key (1:N). Total = 2.

Topic FAQs

How do I decide where to put the foreign key for a 1:N relationship?

Put the primary key of the "one" side as a foreign key in the table of the "many" side. Every row on the N side then points to at most one row on the 1 side.

What is the primary key of a weak entity?

The primary key of its owner entity combined with the weak entity’s own discriminator (partial key). The owner part is also a foreign key.

Does every relationship create a new table?

No. Only M:N relationships (and ternary or higher-degree ones) need their own table. 1:N and 1:1 relationships are folded into an existing table with a foreign key.

What is the difference between total and partial participation?

Total participation (double line) means every entity of the set must appear in at least one relationship instance; partial participation (single line) allows entities that take part in none.

Quick revision · 8 cards

8 flashcards — ER Model

Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.

Q1 Symbols for weak entity and identifying relationship?
Q2 How is a multivalued attribute mapped?
Q3 Where does the foreign key go for 1:N?
Q4 When does a relationship need its own table?
Q5 Total vs partial participation?
Q6 Primary key of a weak entity table?
Q7 What is the degree of a relationship?
Q8 What happens to derived and composite attributes?