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.
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.
| Symbol | Meaning |
|---|---|
| Rectangle | strong entity set |
| Double rectangle | weak entity set |
| Diamond | relationship set |
| Double diamond | identifying relationship of a weak entity |
| Ellipse / double ellipse / dashed ellipse | attribute / multivalued attribute / derived attribute |
| Single line / double line | partial 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|
| Cardinality | Key of relationship set | Max instances (|A| = n, |B| = m) | Typical mapping |
|---|---|---|---|
| 1:1 | key of A or key of B | min(n, m) | FK in either table, or merge |
| 1:N (A one, B many) | key of B | m | key of A as FK in B |
| N:1 (A many, B one) | key of A | n | key of B as FK in A |
| M:N | key of A + key of B | n * m | separate 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).
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 construct | Relational mapping | Extra table? |
|---|---|---|
| Strong entity set | one table, primary key = key attribute | yes (its own) |
| Weak entity set | table with owner key + discriminator as key | yes (its own) |
| Multivalued attribute | table(owner key, value) | yes |
| M:N relationship | table(key of A, key of B, attrs) | yes |
| 1:N relationship | foreign key (one-side key) in N-side table | no |
| 1:1 relationship | foreign key in either table or merge | no |
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.
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)
| Situation | Tables | Reason |
|---|---|---|
| E1 - E2 is 1:1, total on both sides | 1 | merge both entity sets into one table |
| E1 - E2 is 1:1, total on E1 only | 2 | FK of E2 key in E1; no merge needed |
| Weak entity W (1:N identifying) owned by E | 2 | E table + W table; no table for the relationship |
| Entity with one multivalued attribute | 2 | entity table + (key, value) table |
| Ternary M:N:N among E1, E2, E3 | 4 | three 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).
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.
8 GATE-style MCQs for ER Model with full explanations. Attempt each question before revealing the answer.
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?
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.
Department and Employee have a 1:N relationship (one department, many employees) and Employee participates totally. The minimum number of tables is:
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.
The primary key of a weak entity set is formed by:
Show answer & explanation
Answer: C
A weak entity is identified by its owner’s key plus its own partial key (discriminator).
Person(ssn, name, phone) where phone is multivalued. Mapping to the relational model needs a minimum of how many tables?
Show answer & explanation
Answer: B
Person(ssn, name) and PersonPhone(ssn, phone). The multivalued attribute is moved to its own table.
In an ER diagram, a double line connecting an entity set to a relationship set indicates:
Show answer & explanation
Answer: B
A double line means every entity of the set must participate in the relationship (total participation).
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:
Show answer & explanation
Answer: B
E1, E2 (with E1’s key as foreign key), E3 and the table for R2 give 4 tables.
In a 1:N relationship between X (one) and Y (many), the foreign key is placed in:
Show answer & explanation
Answer: B
The key of the one side (X) is stored in the many side (Y) as a foreign key.
A relationship set Supervises between Employee and Employee (a manager supervises many employees, each employee has at most one manager) is mapped to:
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.
Extra page-specific practice beyond the GATE samples. Attempt all 8, then reveal answers to check your reasoning.
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:
Show answer & explanation
Answer: C) (eid, dname)
Owner key eid together with the discriminator dname identifies a dependent; age is not needed.
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?
Show answer & explanation
Answer: A) 1
Because both sets participate totally in a 1:1 relationship, they can be merged into a single table.
A ternary M:N:N relationship among three entity sets is mapped to a table whose primary key is:
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.
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:
Show answer & explanation
Answer: D) 24
Every A entity can relate to every B entity: 4 * 6 = 24.
In a 1:1 relationship between A (4 entities) and B (6 entities), the maximum number of relationship instances is:
Show answer & explanation
Answer: A) 4
Each entity takes part in at most one instance, so the maximum is min(4, 6) = 4.
Which of the following is NOT stored as a column in the relational table of an entity?
Show answer & explanation
Answer: B) derived attribute
Derived attributes are computed from other attributes and are normally not stored.
A weak entity set must participate in its identifying relationship with:
Show answer & explanation
Answer: B) total participation
A weak entity cannot exist without its owner, so its participation in the identifying relationship is total.
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:
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.
Hover a card to reveal the answer with a 3D flip. On touch devices, tap the card or use Show answer.