What a relational database is: tables (relations) with keys that identify rows and constraints that keep the data consistent. Then the ER model, the diagram you draw before you build any tables, and the rules for turning it into the fewest tables possible. GATE asks about keys, NULLs and foreign keys almost every year, and about ER-to-table conversion in 2026.
You need: sets (elements, subsets, no duplicates) from the maths refreshers. No earlier database knowledge.
Relations, keys and integrity constraints
A relational database stores data in tables; a key is a set of columns whose values identify each row, and constraints are rules the database enforces on every insert, delete and update.
GATE asks you to decide what is a candidate key, what can be NULL, and which operations can break a foreign key (2025 Q56, 2026 Q26). The same ideas reappear in every later chapter: joins match keys, and normal forms are defined by keys.
It’s like the league’s registration desk: every player gets a unique player ID (a key), and you can’t register a player for a team that doesn’t exist (a foreign key).
Keys and constraints on a given schema; which operations violate a foreign key.
The Data Premier League keeps its data in tables like these. Team codes keep the tables narrow: KK is Kalinga Kernels, HH Haryana Heuristics, BB Bengaluru Backprops, NN Nagpur Neural Nets, HY Hyderabad Hyperplanes.
| team | city |
|---|---|
| KK | Bhubaneswar |
| HH | Gurugram |
| BB | Bengaluru |
| NN | Nagpur |
| HY | Hyderabad |
| pid | name | team |
|---|---|---|
| P1 | Aarav | KK |
| P2 | Diya | KK |
| P3 | Kabir | HH |
| P4 | Meera | BB |
| P5 | Rohan | NN |
| P6 | Sana | BB |
- A relation is a table. Its schema is its name and column list, e.g. Player(pid, name, team); its instance is the set of rows it holds right now.
- A tuple is a row; an attribute is a column; an attribute’s domain is its set of allowed values (its data type, such as
INT,CHAR(12),VARCHAR(32),DATE). - Degree (arity) = number of columns; cardinality = number of rows. Player above has degree 3 and cardinality 6.
- A relation is a set of tuples: no two rows are identical, and the order of rows doesn’t matter.
- NULL means “unknown or not applicable”. It is not zero and not the empty string, and any comparison with NULL is unknown, never true (Part 3 uses this).
- A superkey is a set of attributes whose values are never repeated: no two rows agree on all of them. {pid} and {pid, name} are superkeys of Player.
- A candidate key is a minimal superkey: remove any attribute and it stops being a superkey. {pid} is one; {pid, name} is not (name is unnecessary).
- The primary key is the candidate key the designer picks (underlined in schemas). It must be unique and NOT NULL. The other candidate keys are alternate keys.
- A foreign key is an attribute (or set) in one relation whose values must appear as a key of another relation, or be NULL. Player.team is a foreign key referencing Team.team. Player is the referencing (child) relation, Team the referenced (parent).
- An attribute that belongs to some candidate key is prime; the others are non-prime (Part 4 needs this).
- Domain constraint: every value comes from the attribute’s type (plus any
CHECKcondition, e.g.CHECK (runs >= 0)). - Key constraint: no two rows share a candidate key value (
PRIMARY KEY,UNIQUE). - Entity integrity: a primary key attribute can never be NULL.
- Referential integrity: every non-NULL foreign key value must exist in the referenced key. A foreign key column itself may be NULL unless it is declared
NOT NULL.
A foreign key is a pointer from the child (Player) to the parent (Team). Ask: can this operation create a dangling pointer?
- Insert into the child: yes, if the new row points to a parent that doesn’t exist.
- Delete from the child: never; you only remove pointers.
- Insert into the parent: never; nothing points to a brand-new row yet.
- Delete from the parent: yes, if some child still points to it. The database then rejects it (
RESTRICT), deletes the children too (ON DELETE CASCADE) or sets their pointer to NULL (ON DELETE SET NULL). - Updates behave like a delete followed by an insert, so they can break it from either side.
Apply operations to the league’s tables and see which constraint (if any) rejects them. Try inserting player P8 for Chennai Classifiers before and after inserting that team. Then delete Nagpur Neural Nets under each of the three ON DELETE policies, and confirm that deleting a player or inserting a team is never rejected.
Consider the following two relations, named Customer and Person, in a database:
Person (
aadhaar CHAR(12) PRIMARY KEY,
name VARCHAR(32));
Customer (
name VARCHAR(32),
email VARCHAR(32) PRIMARY KEY,
phone CHAR(10),
aadhaar CHAR(12),
FOREIGN KEY (aadhaar) REFERENCES Person(aadhaar));
Which of the following statements is/are correct?
- aadhaar is a candidate key in the Customer relation
- phone can be NULL in the Customer relation
- aadhaar is a candidate key in the Person relation
- aadhaar can be NULL in the Person relation
(A) In Customer, aadhaar is only a foreign key. Nothing declares it
UNIQUE, so one person could appear as two customers with two emails, and aadhaar would repeat. Not a candidate key: false.A foreign key points to a key elsewhere; it need not be unique in its own table.
(B) phone has no
NOT NULLand is not part of the primary key, so it may be NULL: true.Without a constraint saying otherwise, any non-key column accepts NULL.
(C) In Person, aadhaar is the primary key, and a primary key is a candidate key: true. (D) A primary key can never be NULL (entity integrity): false. Answer: B, C.
Official key: B; C.
Consider two relations r and s defined on the relational schemas R(A,B) and S(E,C), respectively. A is the primary key of R and E is a foreign key of S referencing A in R. Which of the following operations will NEVER violate the foreign key constraint?
- Inserting records into relation r
- Deleting records from relation s
- Deleting records from relation r
- Inserting records into relation s
s is the child (it holds the pointer E), r is the parent. Which operations can leave a pointer with nothing to point to?
Inserting into the parent r (A) and deleting from the child s (B) can never create a dangling reference. Deleting from r (C) can, if some row of s still references the deleted A value; inserting into s (D) can, if the new E value doesn’t exist in r. Answer A, B. Official key: A; B.
A relation R(A, B, C, D) has exactly one candidate key, {A}. How many superkeys does R have?
A superkey is any set of attributes that contains a candidate key. Which sets contain A?
A superkey must contain A; each of B, C and D can be in or out freely: $2^3 = 8$ superkeys ({A}, {A,B}, …, {A,B,C,D}).
A relation R(A, B, C) has candidate keys {A} and {B, C}. How many superkeys does it have?
Count the sets containing A, then add the sets containing both B and C but not A (so you don’t count any set twice).
Sets containing A: {A}, {A,B}, {A,C}, {A,B,C}, which is 4. Sets containing B and C but not A: {B,C}, which is 1. Total 5.
Team has 5 rows. Player has 40 rows, and Player.team is a nullable foreign key referencing Team.team. At most how many distinct non-NULL values can Player.team contain?
Every non-NULL foreign key value must already exist in Team.team.
Referential integrity limits the non-NULL values to the 5 team keys, so at most 5 distinct values (the 40 players share them). NULLs are allowed too, since the column is nullable.
The league’s database has four tables, with foreign-key checking switched on:
Team(team PRIMARY KEY, city)
Player(pid PRIMARY KEY,
team REFERENCES Team(team) ON DELETE CASCADE)
Score(pid REFERENCES Player(pid) ON DELETE CASCADE,
match, runs, PRIMARY KEY (pid, match))
Sponsor(sid PRIMARY KEY,
pid REFERENCES Player(pid) ON DELETE SET NULL)| team | city |
|---|---|
| KK | Bhubaneswar |
| HH | Gurugram |
| BB | Bengaluru |
| NN | Nagpur |
| pid | team |
|---|---|
| P1 | KK |
| P2 | KK |
| P3 | HH |
| P4 | BB |
| P5 | BB |
| P6 | NN |
| pid | match | runs |
|---|---|---|
| P1 | m1 | 40 |
| P1 | m2 | 12 |
| P2 | m1 | 7 |
| P4 | m1 | 55 |
| P4 | m2 | 30 |
| P5 | m2 | 18 |
| P6 | m1 | 25 |
| sid | pid |
|---|---|
| S1 | P1 |
| S2 | P4 |
| S3 | P5 |
| S4 | NULL |
The statement DELETE FROM Team WHERE team = 'BB'; is executed. How many rows are left in the four tables together, and how many Sponsor rows then have a NULL pid?
Follow the delete along each foreign key in turn. Which players go with BB, and what happens to the rows that point to those players? Don’t forget the NULL that was there before.
Before the delete there are 4 + 6 + 7 + 4 = 21 rows.
The BB row of Team goes (1 row). Player.team is ON DELETE CASCADE, so P4 and P5 go too (2 rows).
Their deletion cascades again through Score.pid: P4’s two innings and P5’s one innings go (3 rows). Sponsor.pid is ON DELETE SET NULL, so S2 and S3 stay, with pid set to NULL.
Rows left: 21 − 1 − 2 − 3 = 15. Sponsor rows with a NULL pid: S2, S3 and S4 (already NULL) = 3.
Stopping the cascade at Player gives 18; treating SET NULL like CASCADE gives 13.
Two tables are declared as follows. The foreign key uses the default policy, which rejects any change that would break it.
Team(team CHAR(2) PRIMARY KEY, city VARCHAR(20) UNIQUE)
Player(pid CHAR(2) PRIMARY KEY, email VARCHAR(30) UNIQUE,
team CHAR(2) NOT NULL REFERENCES Team(team))| team | city |
|---|---|
| KK | Bhubaneswar |
| HH | NULL |
| pid | team | |
|---|---|---|
| P1 | a@dpl.in | KK |
| P2 | NULL | KK |
Each operation below is applied on its own to the data shown. Which of them is/are rejected?
INSERT INTO Team VALUES ('BB', NULL);UPDATE Player SET team = 'HH' WHERE pid = 'P2';INSERT INTO Player VALUES ('P3', 'a@dpl.in', 'HH');DELETE FROM Team WHERE team = 'KK';
Check each operation against every constraint it could touch: PRIMARY KEY, UNIQUE (how does it treat NULL?), NOT NULL and the foreign key. Decide which table is the parent before judging the delete.
(A) Accepted. UNIQUE forbids two equal non-NULL values, but NULL is not equal to anything, so a second NULL city is allowed.
(B) Accepted. P2 now points to HH, which exists, and team stays non-NULL. No table points to Player, so changing P2 can’t break anything else.
(C) Rejected. The email a@dpl.in already belongs to P1, so the UNIQUE constraint fails (the team HH is fine).
(D) Rejected. P1 and P2 still reference KK, and the policy is to reject. (Deleting HH would be accepted: no player points to it.)
Correct: C, D.
A relation R(A, B, C, D, E) has exactly three candidate keys: {A, B}, {B, C} and {D}. How many superkeys does R have?
A superkey is any set of attributes that contains at least one candidate key. Count the sets containing each key, then use inclusion–exclusion for sets that contain two or three keys.
Sets containing {A, B}: the other 3 attributes are free, so $2^3 = 8$. Containing {B, C}: also 8. Containing {D}: $2^4 = 16$.
Overlaps: containing both {A, B} and {B, C} means containing ABC, so $2^2 = 4$; {A, B} and {D}: ABD, 4; {B, C} and {D}: BCD, 4. All three: ABCD, $2^1 = 2$.
Superkeys $= 8 + 8 + 16 - 4 - 4 - 4 + 2 =$ 22.
Simply adding gives 32, and forgetting to add back the triple overlap gives 20.
- Underline the primary key of every schema you’re given, and mark foreign keys with an arrow to their parent.
- For “can X be NULL?”, look for PRIMARY KEY or NOT NULL; otherwise the answer is yes.
- For foreign key questions, decide which table is the child before reading the options.
- Assuming a foreign key column must be unique. Many players share one team.
- Calling {pid, name} a candidate key: it’s a superkey, but not minimal.
- Treating NULL as 0 or as an empty string.
- Superkey = no two rows agree on it; candidate key = minimal superkey; primary key = the chosen candidate key, unique and never NULL.
- A foreign key value must exist in the parent’s key or be NULL; it doesn’t have to be unique.
- Inserting into the parent and deleting from the child never break a foreign key; the other two operations can.
Player(pid, name, team) has 6 rows. Its degree and cardinality are
Which of these can never be NULL?
Deleting a Team row that players still reference, under ON DELETE CASCADE,
The ER model, and turning it into tables
An entity–relationship (ER) model describes the things you store (entities), their properties (attributes) and how they are connected (relationships); a short list of mapping rules turns it into relations.
GATE 2026 Q61 asked for the minimum number of relations an ER model needs, and the answer depends on exactly these rules: multivalued attributes and many-to-many relationships each need their own table.
It’s like a seating plan sketched before a wedding: first who’s coming and who knows whom, then the actual tables. Getting the sketch right means fewer tables and no repeated information.
Counting the relations an ER model needs; reading cardinality and participation.
- An entity is a thing (a player); an entity set is all things of that kind (Player). Drawn as a rectangle.
- Attributes (ovals): simple or composite (name = first + last); single-valued or multivalued (a sponsor’s several phone numbers, double oval); derived (age from date of birth, dashed oval). The key attribute is underlined.
- A relationship set (diamond) connects entity sets, e.g. Endorses between Player and Sponsor. Its degree is the number of entity sets it connects (binary = 2).
- Cardinality ratio: 1 : 1, 1 : N or M : N, the maximum number of partners on each side.
- Participation: total (double line: every entity must take part) or partial (single line). Total participation means “at least one”, cardinality means “at most”.
- A weak entity (double rectangle) has no key of its own; it’s identified by its owner’s key plus a partial key, e.g. Innings identified by (match id, innings number).
- Strong entity → one relation with its simple attributes. Composite attributes are flattened into their parts; derived attributes are dropped.
- Weak entity → one relation with its attributes plus the owner’s key; primary key = owner key + partial key.
- 1 : N relationship → no new relation: put the “1” side’s key as a foreign key in the “N” side’s relation (plus any relationship attributes).
- 1 : 1 relationship → a UNIQUE foreign key on one side (prefer the side with total participation, so it’s never NULL). If both sides are total, the two entities can be merged into one relation.
- M : N relationship → always a new relation holding both keys (together the primary key) and the relationship’s attributes. Participation doesn’t change this.
- Multivalued attribute → a new relation (owner key, value), with both columns as the key.
- n-ary relationship (degree 3 or more) → a new relation with all the participating keys.
Minimum relations = (entity sets) + (multivalued attributes) + (M : N and n-ary relationships) − (1 : 1 relationships with total participation on both sides, which merge). 1 : N relationships add nothing. Every relation produced this way is already in 3NF when there are no other functional dependencies.
Change the cardinality, participation and attributes of the Endorses relationship between Player and Sponsor, and watch the relation list and count change. Find the settings that need the most relations, and the one setting where a 1 : 1 relationship collapses two entities into a single table.
Consider an ER model with the entities E1(A11,A12,A13) and E2(A21,A22,A23), where, A11, A12, A13 are the attributes of E1, and A21, A22, A23 are the attributes of E2. Let A22 be a multi-valued attribute. A11 and A21 are the primary keys of E1 and E2, respectively.
Let R12 be a many-to-many relationship between E1 and E2. Participation of both E1 and E2 in R12 is total.
The minimum number of relations required to convert the ER model into relational model (assuming there is no other functional dependency) where each relation is in third normal form (3NF) is __________ . (Answer in integer)
Each entity gets a relation: E1(A11, A12, A13) and E2(A21, A23).
A22 leaves E2, because a column can hold only one value per row.
The multivalued attribute gets its own relation: E2_A22(A21, A22).
One row per (entity, value) pair.
R12 is many-to-many, so it needs R12(A11, A21). Total participation on both sides doesn’t let you merge an M : N relationship into either entity. Total: 4 relations, each in 3NF.
Merging is possible only for 1 : 1 with total participation on both sides. Official key: 4.
Entities: Team(tid, name) and Player(pid, name, nickname), where nickname is multivalued. Relationship PlaysFor: each player plays for exactly one team; a team has many players. What is the minimum number of relations?
PlaysFor is N : 1. Where does the team’s key go? And the multivalued attribute?
Team(tid, name), Player(pid, name, tid), PlayerNickname(pid, nickname). The N : 1 relationship becomes the foreign key tid inside Player, so 3 relations.
Entities Player, Match and Ground, each with a key and simple attributes only. Player and Match are related by an M : N relationship PlaysIn; each match is held at exactly one ground (Match : Ground is N : 1). What is the minimum number of relations?
Three entities, one M : N relationship, one N : 1 relationship.
Player, Match (with the ground’s key as a foreign key), Ground, and PlaysIn(pid, mid): 3 + 1 = 4.
Innings is a weak entity owned by Match(mid, date), with partial key innings_no (1 or 2). What is the primary key of the relation for Innings?
The partial key only distinguishes innings within one match.
(mid, innings_no): the owner’s key plus the partial key. innings_no alone repeats across matches, and mid alone repeats within a match.
Two entity sets with simple attributes only are linked by a 1 : 1 relationship, with total participation on both sides. There are no other entities, relationships or multivalued attributes. What is the minimum number of relations?
Every entity on each side has exactly one partner.
Each row of one entity pairs with exactly one row of the other, so both can live in one merged relation (either key works as the primary key): 1 relation.
The league’s ER model has these parts:
- Team(tid, name) and Coach(cid, name), linked by Manages: 1 : 1, with total participation on both sides.
- Player(pid, name, dob, age, phone), where age is derived from dob and phone is multivalued. PlaysFor links each player to exactly one team (Player : Team is N : 1).
- Sponsor(sid, name), linked to Player by Endorses: M : N, with a relationship attribute fee.
- Match(mid, date), which owns the weak entity Innings (partial key no, attribute runs) through the identifying relationship Has (1 : N).
Assuming no other functional dependencies, what is the minimum number of relations needed, with each relation in 3NF?
Apply one mapping rule to each piece: entities (strong and weak), the multivalued attribute, and each relationship according to its cardinality and participation. Only one of the relationships lets two entities share a table.
Manages is 1 : 1 with total participation on both sides, so Team and Coach merge: TeamCoach(tid, name, cid, coach_name), with cid also a candidate key. (1)
Player(pid, name, dob, tid): age is derived, so it’s dropped; PlaysFor is N : 1, so it becomes the foreign key tid. (2) The multivalued phone needs PlayerPhone(pid, phone). (3)
Sponsor(sid, name) (4), and the M : N Endorses needs Endorses(pid, sid, fee). (5)
Match(mid, date) (6) and Innings(mid, no, runs) (7). The identifying relationship Has needs no table: it’s the mid inside Innings.
Total 7. Common slips: 8 (not merging Team and Coach), 9 (also giving PlaysFor a table), 10 (also giving Has one).
Match(mid, date) owns the weak entity Innings, with partial key no. Innings in turn owns the weak entity Ball, with partial key ball_no and attribute runs. Every ball is bowled by exactly one Player(pid, name), and a player bowls many balls (BowledBy, Ball : Player is N : 1). In the relation for Ball, what is the primary key, and how many columns does it have?
- (ball_no); 3 columns
- (no, ball_no); 4 columns
- (mid, no, ball_no); 5 columns
- (mid, no, ball_no, pid); 5 columns
A weak entity’s key is its owner’s key plus its own partial key. What is the owner’s key here, given that the owner is itself weak? Then decide where BowledBy goes.
Innings is identified by (mid, no). Ball’s owner is Innings, so Ball’s key is (mid, no) plus ball_no: (mid, no, ball_no).
Columns: mid, no, ball_no, runs, plus the bowler’s pid, because an N : 1 relationship becomes a foreign key on the N side. That’s 5 columns. Answer (C).
(A) treats Ball as a strong entity, and (B) forgets that Innings is weak too. (D) puts pid into the key, but each ball has exactly one bowler, so (mid, no, ball_no) already identifies the row and the bigger set isn’t minimal.
An ER model has Player(pid, name), Locker(lid, room) and Team(tid, name). AssignedTo links Player and Locker 1 : 1: every locker is assigned to exactly one player, but some players have no locker. PlaysFor links Player and Team N : 1, and some players (free agents) have no team. Which of the following is/are correct?
- AssignedTo can be stored as a column pid in Locker, declared UNIQUE and NOT NULL.
- Player and Locker can be merged into one relation, keyed by pid, that never needs a NULL.
- Because some players have no team, PlaysFor needs a relation of its own.
- The minimum number of relations for this model is 3.
Participation decides two things: whether a foreign key column may be NULL, and whether two entities can share one relation. Cardinality decides where the foreign key goes.
(A) True. Locker has total participation, so pid in Locker is never NULL; UNIQUE stops two lockers going to the same player, which keeps the relationship 1 : 1.
(B) False. A player without a locker would need NULL lid and room in a merged table. A merge with no NULLs needs total participation on both sides.
(C) False. Partial participation only means the foreign key tid in Player can be NULL. N : 1 never needs its own relation.
(D) True. Player(pid, name, tid), Locker(lid, room, pid) and Team(tid, name).
Correct: A, D.
- List entities, multivalued attributes and relationships separately, then apply one rule to each.
- Check cardinality before participation: only 1 : 1 with total participation on both sides can merge.
- Put the foreign key on the N side of a 1 : N relationship.
- Giving every relationship its own table: 1 : N and 1 : 1 don’t need one.
- Merging an M : N relationship because participation is total.
- Keeping a multivalued attribute as a column (that breaks 1NF).
- Entities → relations; multivalued attributes and M : N (or n-ary) relationships → their own relations.
- 1 : N → foreign key on the N side; 1 : 1 → UNIQUE foreign key, or a merge if both sides are total.
- A weak entity’s key is its owner’s key plus its partial key.
Total participation of Player in PlaysFor means
A derived attribute such as age (computed from date of birth) is mapped to
An M : N relationship with an attribute (fee) becomes
In R(A, B, C), {A, B} is a superkey and neither {A} nor {B} is. Then {A, B} is
Which insert is rejected? Team(team) holds KK and HH; Player(pid, team → Team) holds (P1, KK).
Entities A and B (simple attributes) have an M : N relationship and A has one multivalued attribute. The minimum number of relations is
In a 1 : N relationship between Team (1) and Player (N), the foreign key goes in