GATE Data Science & AIGATE DA
Module 7 · Databases & warehousing

Databases and warehousing, one table at a time

Databases carried 7 marks in 2024, 11 in 2025 and 18 in 2026, and nearly every question is mechanical once you know the rules: count the rows a query returns, find the candidate keys, insert a key into a B+ tree, count the cuboids. This module teaches each rule on small tables from the Data Premier League, then works through every DA database question asked so far.

You need: sets and logic from the maths refreshers (union, intersection, difference, subsets). Part 5’s normalisation recalls z-scores from statistics, and the B+ tree builds on the search trees in Python & DSA.

The route

    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).

    Where it shows up in GATE DA

    Keys and constraints on a given schema; which operations violate a foreign key.

    2025 Q56 · candidate keys, NULLs, foreign keys2026 Q26 · operations that never violate a foreign key2024 Q31 · a foreign key used in a join
    Heat: every year, 1–2 marks

    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
    teamcity
    KKBhubaneswar
    HHGurugram
    BBBengaluru
    NNNagpur
    HYHyderabad
    Player
    pidnameteam
    P1AaravKK
    P2DiyaKK
    P3KabirHH
    P4MeeraBB
    P5RohanNN
    P6SanaBB
    • 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 CHECK condition, 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.
    Try it

    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.

    GATE DA 2025 · Q56 · MSQ · 2 marks

    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?

    1. aadhaar is a candidate key in the Customer relation
    2. phone can be NULL in the Customer relation
    3. aadhaar is a candidate key in the Person relation
    4. aadhaar can be NULL in the Person relation
    1. (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.

    2. (B) phone has no NOT NULL and is not part of the primary key, so it may be NULL: true.

      Without a constraint saying otherwise, any non-key column accepts NULL.

    3. (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.

    GATE DA 2026 · Q26 · MSQ · 1 mark

    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?

    1. Inserting records into relation r
    2. Deleting records from relation s
    3. Deleting records from relation r
    4. 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
    teamcity
    KKBhubaneswar
    HHGurugram
    BBBengaluru
    NNNagpur
    Player
    pidteam
    P1KK
    P2KK
    P3HH
    P4BB
    P5BB
    P6NN
    Score
    pidmatchruns
    P1m140
    P1m212
    P2m17
    P4m155
    P4m230
    P5m218
    P6m125
    Sponsor
    sidpid
    S1P1
    S2P4
    S3P5
    S4NULL

    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
    teamcity
    KKBhubaneswar
    HHNULL
    Player
    pidemailteam
    P1a@dpl.inKK
    P2NULLKK

    Each operation below is applied on its own to the data shown. Which of them is/are rejected?

    1. INSERT INTO Team VALUES ('BB', NULL);
    2. UPDATE Player SET team = 'HH' WHERE pid = 'P2';
    3. INSERT INTO Player VALUES ('P3', 'a@dpl.in', 'HH');
    4. 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.
    1. Superkey = no two rows agree on it; candidate key = minimal superkey; primary key = the chosen candidate key, unique and never NULL.
    2. A foreign key value must exist in the parent’s key or be NULL; it doesn’t have to be unique.
    3. 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

    6 and 3
    Degree counts columns, cardinality counts rows.
    3 and 6
    3 attributes (degree), 6 tuples (cardinality).
    3 and 3
    Count the rows for cardinality.

    Which of these can never be NULL?

    A foreign key attribute
    A foreign key may be NULL unless it is declared NOT NULL.
    An alternate key attribute
    UNIQUE columns accept NULL in SQL unless they’re also NOT NULL.
    A primary key attribute
    Entity integrity: the primary key identifies the row, so it must be known.

    Deleting a Team row that players still reference, under ON DELETE CASCADE,

    is rejected
    That’s RESTRICT, the default behaviour.
    also deletes those players
    CASCADE propagates the delete to the referencing rows.
    sets those players’ team to NULL
    That’s ON DELETE SET NULL.

    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.

    Where it shows up in GATE DA

    Counting the relations an ER model needs; reading cardinality and participation.

    2026 Q61 · minimum relations in 3NF from an ER model
    Heat: 2026, 2 marks (a GATE CS favourite, now in DA)
    • 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).
    1. Strong entity → one relation with its simple attributes. Composite attributes are flattened into their parts; derived attributes are dropped.
    2. Weak entity → one relation with its attributes plus the owner’s key; primary key = owner key + partial key.
    3. 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).
    4. 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.
    5. M : N relationship → always a new relation holding both keys (together the primary key) and the relationship’s attributes. Participation doesn’t change this.
    6. Multivalued attribute → a new relation (owner key, value), with both columns as the key.
    7. 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.

    Try it

    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.

    GATE DA 2026 · Q61 · NAT · 2 marks

    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)

    1. 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.

    2. The multivalued attribute gets its own relation: E2_A22(A21, A22).

      One row per (entity, value) pair.

    3. 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?

    1. (ball_no); 3 columns
    2. (no, ball_no); 4 columns
    3. (mid, no, ball_no); 5 columns
    4. (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?

    1. AssignedTo can be stored as a column pid in Locker, declared UNIQUE and NOT NULL.
    2. Player and Locker can be merged into one relation, keyed by pid, that never needs a NULL.
    3. Because some players have no team, PlaysFor needs a relation of its own.
    4. 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).
    1. Entities → relations; multivalued attributes and M : N (or n-ary) relationships → their own relations.
    2. 1 : N → foreign key on the N side; 1 : 1 → UNIQUE foreign key, or a merge if both sides are total.
    3. A weak entity’s key is its owner’s key plus its partial key.

    Total participation of Player in PlaysFor means

    each player plays for at most one team
    That’s a cardinality limit (“at most”), not participation.
    every player plays for at least one team
    Total = every entity takes part at least once.
    every team has at least one player
    That’s Team’s participation, on the other side.

    A derived attribute such as age (computed from date of birth) is mapped to

    its own relation
    That’s the rule for multivalued attributes.
    a foreign key
    Foreign keys come from relationships.
    nothing: it’s computed when needed
    Storing it would duplicate information already held in date of birth.

    An M : N relationship with an attribute (fee) becomes

    a fee column in one entity’s relation
    One entity row can have many partners, each with its own fee.
    a relation (key1, key2, fee) with key (key1, key2)
    Each pair of partners gets one row and one fee.
    two foreign keys, one in each entity
    A single column can’t hold many partners.

    In R(A, B, C), {A, B} is a superkey and neither {A} nor {B} is. Then {A, B} is

    not a key at all
    It is a superkey by assumption.
    a candidate key
    It is a superkey and no proper subset is: minimal.
    necessarily the primary key
    The primary key is the designer’s choice among candidate keys.

    Which insert is rejected? Team(team) holds KK and HH; Player(pid, team → Team) holds (P1, KK).

    (P2, HH)
    P2 is new and HH exists.
    (P3, NULL)
    A nullable foreign key may be NULL.
    (P1, HH)
    P1 already exists: the primary key would repeat.

    Entities A and B (simple attributes) have an M : N relationship and A has one multivalued attribute. The minimum number of relations is

    2
    The M : N relationship and the multivalued attribute each need a table.
    3
    You’ve missed one of the two extra tables.
    4
    A, B, the M : N relationship and the multivalued attribute.

    In a 1 : N relationship between Team (1) and Player (N), the foreign key goes in

    Player
    Each player has one team, so one column holds it.
    Team
    A team has many players; one column can’t hold them all.
    a new relation
    Possible, but not needed: that’s for M : N.

    The two formal query languages in the syllabus. Relational algebra builds an answer step by step from a few operators (select, project, join, union, difference, division). Tuple relational calculus describes the answer with a logical condition instead. GATE asks you to evaluate expressions on small tables and count the rows, every year.

    You need: Part 1 (relations and keys); set union, intersection and difference from the refreshers.

    Relational algebra: queries as a pipeline of operators

    Relational algebra is a set of operators that each take one or two relations and return a new relation, so you can chain them: filter rows, keep columns, combine tables.

    It’s the most-asked database topic in GATE DA: interpreting an expression (2025 Q17), writing one (2024 Q26), and evaluating one on given tables (2025 Q62, 2026 Q42), including the tricky division operator.

    It’s like a kitchen recipe: each step takes ingredients and hands a new dish to the next step. Read an expression from the innermost brackets outwards, exactly like a recipe.

    Where it shows up in GATE DA

    Evaluate on tables and count tuples; match an expression to its meaning; properties of × and ÷.

    2026 Q42 · σ and natural joins on three tables2025 Q62 · division2025 Q17 · what does this expression compute?2024 Q26 · write a containment checkSample Q14 · cross join sizeSample Q15 · size of a division
    Heat: every year, 1–4 marks
    • Selection $\sigma_{c}(R)$: the rows of R that satisfy condition c. Same columns; at most |R| rows.
    • Projection $\pi_{A,B}(R)$: only columns A and B, with duplicate rows removed (a relation is a set).
    • Cartesian product $R \times S$: every row of R paired with every row of S. Rows: $|R|\cdot|S|$; columns: degree(R) + degree(S).
    • Natural join $R \bowtie S$: the pairs that agree on all common column names, with one copy of each common column. With no common columns it is just $R \times S$. A theta join $R \bowtie_{c} S = \sigma_c(R \times S)$.
    • Union $R \cup S$, intersection $R \cap S$, difference $R - S$ (also written $R \setminus S$): ordinary set operations. R and S must be union-compatible (same number of columns with matching domains).
    • Rename $\rho$: gives a relation or its columns new names (needed to join a table with itself).
    • Division $R(x, y) \div S(y)$: the x-values that appear in R with every y in S. Typical phrase: "players who have played at all grounds".
    • $\sigma$ and $\pi$ never increase the number of rows. $0 \le |R \bowtie S| \le |R|\cdot|S|$.
    • Division in terms of the basic operators: $R \div S = \pi_x(R) - \pi_x\big((\pi_x(R) \times S) - R\big)$. Read it as: candidates, minus the candidates missing at least one required y.
    • $|R \div S| \le |\pi_x(R)| \le |R|$.
    • Intersection is not basic: $R \cap S = R - (R - S)$. The basic set is $\{\sigma, \pi, \times, \cup, -, \rho\}$.
    • “Every A is in B” is checked by $A - B = \varnothing$.
    Try it

    Step through each operator on the league’s tables. In “× and ⋈”, count the 30 rows of the product and see which 6 survive the join. In “÷ division”, follow the five steps of the formula above and see why only P1 and P4 played at every ground.

    GATE DA 2026 · Q42 · MCQ · 2 marks

    Consider the given relations $X$, $Y$ and $Z$. The relation $X$ has three columns $P$, $Q$ and $R$. The relation $Y$ has three columns $P$, $Q$ and $S$. The relation $Z$ has two columns $P$ and $T$.

    X
    PQR
    P1Q1R1
    P2Q2R2
    P3Q3R2
    Y
    PQS
    P1Q12
    P1Q25
    P2Q16
    P3Q31
    Z
    PT
    P1T1
    P3T2
    P4T3
    P4NULL

    Consider the relational algebra expression

    $$\prod_{PRS}\Big[\big(\sigma_{(Q = Q3 \,\vee\, R = R2)}[X \bowtie Y]\big) \bowtie \big(\sigma_{(S \gt 1)}[Y \bowtie Z]\big)\Big]$$

    where ⨝ denotes natural join operation. Which of the following options is the correct output for the given expression?

    1. Two rows (P1, R1, 2) and (P1, R1, 5)
    2. Three rows (P1, R1, 2), (P1, R1, 5) and (P2, R2, 6)
    3. One row (P1, R1, 2)
    4. Zero rows
    1. $X \bowtie Y$ matches on both P and Q: (P1, Q1) gives (P1, Q1, R1, 2) and (P3, Q3) gives (P3, Q3, R2, 1). (P2, Q2) has no partner in Y.

      A natural join uses every common column, here P and Q together.

    2. Selecting $Q = Q3 \vee R = R2$ keeps only (P3, Q3, R2, 1).

      The P1 row has Q1 and R1, so it fails both parts of the “or”.

    3. $Y \bowtie Z$ matches on P: (P1, Q1, 2, T1), (P1, Q2, 5, T1), (P3, Q3, 1, T2). P2 has no Z row. Selecting $S \gt 1$ leaves the two P1 rows.

      P4 appears only in Z, so it never joins.

    4. Joining the two results needs equal P, Q and S. The left side has only P3; the right side only P1. No pair matches: (D) zero rows.

      Options (A)–(C) come from skipping the first selection or joining on P alone. Official key: (D).

    GATE DA 2025 · Q62 · NAT · 2 marks

    Consider the following tables, Loan and Borrower, of a bank.

    Loan
    loan numbranch nameamount
    L11Banjara Hills90000
    L14Kondapur50000
    L15SR Nagar40000
    L22SR Nagar25000
    L23Balanagar80000
    L25Kondapur70000
    L19SR Nagar65000
    Borrower
    customer nameloan num
    AnandL11
    KarteekL11
    KarteekL14
    AnkitaL15
    GopalL19
    KarteekL22
    KarteekL23
    SunilL23
    SunilL25

    Query: $\pi_{\text{branch name, customer name}}(\text{Loan} \bowtie \text{Borrower}) \div \pi_{\text{branch name}}(\text{Loan})$ where ⨝ denotes natural join. The number of tuples returned by the above relational algebra query is ______ (Answer in integer)

    The divisor is the set of all branches: Banjara Hills, Kondapur, SR Nagar, Balanagar. Which customer has a loan at every one of them?

    Branches per customer: Anand {Banjara Hills}; Karteek {Banjara Hills (L11), Kondapur (L14), SR Nagar (L22), Balanagar (L23)}; Ankita {SR Nagar}; Gopal {SR Nagar}; Sunil {Balanagar, Kondapur}. Only Karteek covers all four branches, so the result has 1 tuple. Official key: 1.

    GATE DA 2024 · Q26 · MCQ · 1 mark

    Consider a database that includes the following relations: Defender(name, rating, side, goals), Forward(name, rating, assists, goals), Team(name, club, price). Which ONE of the following relational algebra expressions checks that every name occurring in Team appears in either Defender or Forward, where $\phi$ denotes the empty set?

    1. $\Pi_{name}(\text{Team}) \setminus (\Pi_{name}(\text{Defender}) \cap \Pi_{name}(\text{Forward})) = \phi$
    2. $(\Pi_{name}(\text{Defender}) \cap \Pi_{name}(\text{Forward})) \setminus \Pi_{name}(\text{Team}) = \phi$
    3. $\Pi_{name}(\text{Team}) \setminus (\Pi_{name}(\text{Defender}) \cup \Pi_{name}(\text{Forward})) = \phi$
    4. $(\Pi_{name}(\text{Defender}) \cup \Pi_{name}(\text{Forward})) \setminus \Pi_{name}(\text{Team}) = \phi$

    “Every A is in B” means A − B is empty. Here A is the Team names and B is “Defender or Forward”, a union.

    Team names minus (Defender names ∪ Forward names) must be empty: (C). (A) uses ∩, demanding each name be in both; (B) and (D) subtract in the wrong direction. Official key: (C).

    GATE DA 2025 · Q17 · MCQ · 1 mark

    Consider the following three relations: Car (model, year, serial, color), Make (maker, model), Own (owner, serial). A tuple in Car represents a specific car of a given model, made in a given year, with a serial number and a color. A tuple in Make specifies that a maker company makes cars of a certain model. A tuple in Own specifies that an owner owns the car with a given serial number. Keys are underlined; (owner, serial) together form key for Own. (⋈ denotes natural join)

    $\pi_{\text{owner}}(\text{Own} \bowtie (\sigma_{\text{color}=\text{“red”}}(\text{Car} \bowtie (\sigma_{\text{maker}=\text{“ABC”}}\text{Make}))))$

    Which one of the following options describes what the above expression computes?

    1. All owners of a red car, a car made by ABC, or a red car made by ABC
    2. All owners of more than one car, where at least one car is red and made by ABC
    3. All owners of a red car made by ABC
    4. All red cars made by ABC

    Work from the inside out: models made by ABC → cars of those models → the red ones → their owners.

    Each step only narrows the rows, so both conditions apply to the same car (an “and”, not an “or”), and the final projection returns owners, not cars: (C). Official key: (C).

    GATE DA 2024 sample paper · Q14 · MCQ · 1 mark

    Consider two relations R(x, y) and S(x,z). Relation R has 100 records, and relation S has 200 records. What will be the number of attributes and records of the following query? SELECT * from R CROSS JOIN S;

    1. 3 attributes, 20000 records
    2. 4 attributes, 20000 records
    3. 3 attributes, 200 records
    4. 4 attributes, 200 records

    A cross join is the Cartesian product: it does not merge the common column x.

    Columns: R.x, y, S.x, z, which is 4. Rows: 100 × 200 = 20000. Answer (B). A natural join would have merged x into one column. (Sample paper, no official key.)

    GATE DA 2024 sample paper · Q15 · MSQ · 1 mark

    Consider two relations R(x, y) and S(y), and perform the following operation: R(x,y) DIVIDE S(Y). If X is the relation returned by the above operation, which of the following option(s) is/are always TRUE?

    1. $|X| \le |R|$
    2. $|X| \le |S|$
    3. $|X| \le |R|$ AND $|X| \le |S|$
    4. $|X| \gt |R|$

    Every x in the answer must come from some row of R. For (B), try R = {(1, a), (2, a)} and S = {a}.

    X ⊆ π_x(R), so |X| ≤ |R|: (A) is always true and (D) never. In the hint’s example X = {1, 2} has 2 tuples but |S| = 1, so (B) fails, and with it (C). Answer: A only. (Sample paper, no official key.)

    Consider these relations.

    Player
    pidteam
    P1KK
    P2KK
    P3HH
    P4KK
    P5BB
    P6NN
    P7HY
    Plays
    pidgid
    P1G1
    P1G2
    P1G3
    P2G1
    P2G3
    P3G1
    P3G2
    P3G3
    P4G2
    P5G1
    P5G2
    P5G3
    P6G3
    Ground
    gidcity
    G1Pune
    G2Pune
    G3Indore
    G4Indore

    How many tuples does this expression return? (⋈ is the natural join.)

    $$\pi_{team}\Big(\text{Player} \bowtie \big(\pi_{pid}(\text{Plays}) - (\text{Plays} \div \pi_{gid}(\sigma_{city = \text{'Pune'}}(\text{Ground})))\big)\Big)$$

    Work from the inside out. The divisor is the set of Pune grounds. Who has played at all of them? Remove those players from everyone who has played somewhere, then look up the teams.

    $\pi_{gid}(\sigma_{city = \text{'Pune'}}(\text{Ground})) = \{G1, G2\}$.

    Division: P1 (G1, G2, G3) ✓, P2 (G1, G3) ✗, P3 ✓, P4 (G2 only) ✗, P5 ✓, P6 (G3 only) ✗. So Plays ÷ {G1, G2} = {P1, P3, P5}.

    $\pi_{pid}(\text{Plays}) = \{P1, \ldots, P6\}$ (P7 has never played). The difference is {P2, P4, P6}: players who missed at least one Pune ground.

    Joining with Player gives teams KK, KK, NN, and π removes the duplicate: {KK, NN}, so 2 tuples.

    Keeping the duplicate gives 3; using all four grounds as the divisor gives 4 (nobody has played at G4); starting from πpid(Player) wrongly adds P7’s team HY.

    R
    ABC
    1xp
    1yp
    2xq
    3yq
    S
    BCD
    xp10
    xq20
    yp10
    yp30
    zq20

    How many tuples does $\pi_{A, D}(R \bowtie S)$ return, where ⋈ is the natural join?

    1. 3
    2. 4
    3. 7
    4. 20

    R and S share two columns. A natural join matches on both of them at once. Then remember what π does to repeated rows.

    The common columns are B and C. Matching pairs: (1, x, p) with (x, p, 10); (1, y, p) with (y, p, 10) and (y, p, 30); (2, x, q) with (x, q, 20). (3, y, q) has no partner. So $R \bowtie S$ has 4 rows.

    Projected onto (A, D): (1, 10), (1, 10), (1, 30), (2, 20). The repeated (1, 10) appears once in the result, so 3 tuples: answer (A).

    (B) forgets that π removes duplicates. (C) joins on B alone. (D) is $|R|\cdot|S|$, the Cartesian product.

    R
    AB
    1a
    1b
    2a
    3c
    S
    AB
    1a
    2b
    3c
    4a

    For these two relations, which of the following is/are correct? (⋈ is the natural join.)

    1. $\pi_A(R - S)$ has 2 tuples.
    2. $\pi_A(R) - \pi_A(S)$ has 2 tuples.
    3. $R \bowtie S$ has 2 tuples.
    4. $R \div \pi_B(S)$ has 1 tuple.

    Evaluate each expression separately. For (C), R and S have the same columns, so what must a joined pair agree on? For (D), list the B values each A has in R.

    (A) True. $R - S = \{(1, b), (2, a)\}$, so $\pi_A(R - S) = \{1, 2\}$.

    (B) False. $\{1, 2, 3\} - \{1, 2, 3, 4\} = \varnothing$: 0 tuples. Projection does not distribute over difference, which is exactly why (A) and (B) differ.

    (C) True. With every column in common, the natural join keeps rows that agree on everything, which is $R \cap S = \{(1, a), (3, c)\}$.

    (D) False. $\pi_B(S) = \{a, b, c\}$. In R, 1 has {a, b}, 2 has {a} and 3 has {c}: nobody has all three, so 0 tuples.

    Correct: A, C.

    • Evaluate from the innermost brackets outwards, and write down each intermediate table.
    • Before a natural join, list all common column names: the join matches on every one.
    • Translate “every” or “all” into division, and “every A is in B” into A − B = ∅.
    • Forgetting that π removes duplicates.
    • Joining on one common column when two are shared.
    • Letting NULL match NULL in a join: NULL never equals anything.
    1. σ filters rows, π keeps columns (and removes duplicates), × pairs everything, ⋈ pairs rows that agree on all common columns.
    2. Division R ÷ S finds the x-values paired with every y in S: π_x(R) − π_x((π_x(R) × S) − R).
    3. For counting questions, write each intermediate relation; most wrong options come from skipping one condition.

    R has 4 rows and 2 columns; S has 3 rows and 3 columns, with no column names in common. R ⋈ S has

    0 rows
    With no common columns, nothing has to match.
    12 rows and 5 columns
    A natural join with no common columns is the Cartesian product.
    4 rows and 5 columns
    Every R row pairs with every S row.

    πteam(Player) on a 6-row Player table with 4 distinct teams returns

    6 rows
    Relational algebra works on sets.
    4 rows
    Projection removes duplicate rows.
    1 row
    One row per distinct team value.

    “Players who have played at every ground” is written with

    Plays ⋈ Ground
    That lists the (player, ground) pairs that occurred.
    πpid(Plays) ∩ Ground
    These aren’t union-compatible: different columns.
    Plays ÷ Ground
    Division expresses “with every”.

    Tuple relational calculus: describe the answer, not the steps

    Tuple relational calculus (TRC) writes a query as a set: “all tuples t such that some condition holds”, using ∃ (there exists) and ∀ (for all) to talk about other tables.

    GATE 2026 Q59 gave a TRC expression and asked how many tuples it returns. You evaluate it by testing each candidate tuple t in turn, which is exactly what the widget below does.

    It’s like a selector’s brief, “every player who has scored a fifty this season”, instead of a step-by-step procedure for finding them. The brief says what, not how.

    Where it shows up in GATE DA

    Count the tuples a TRC expression returns; match TRC to algebra or SQL.

    2026 Q59 · count the result of a TRC query
    Heat: 2026, 2 marks
    • A query has the form $\{\, t \mid P(t) \,\}$: every tuple t for which the formula P is true.
    • $t \in R$ says t is a row of R; $t[A]$ (or $t.A$) is t’s value in column A.
    • $\exists s \in S\,(\ldots)$: at least one row s of S makes the bracket true. $\forall s \in S\,(\ldots)$: every row of S does.
    • Connectives: ∧ (and), ∨ (or), ¬ (not), ⇒ (implies: $p \Rightarrow q$ is false only when p is true and q is false).
    • A query is safe if its answer is finite and built from values in the database. $\{t \mid \neg(t \in R)\}$ is unsafe: infinitely many tuples are not in R. Safe TRC has exactly the power of relational algebra.
    • $t \in R \wedge \exists s \in S\,(s[A] = t[A] \wedge c)$: a semi-join. Keep t if it has at least one matching S row satisfying c. Duplicates don’t multiply t.
    • $t \in R \wedge \neg\exists s \in S\,(s[A] = t[A])$: rows of R with no match (algebra: difference).
    • $t \in R \wedge \forall s \in S\,(s[A] = t[A] \Rightarrow c)$: every matching S row satisfies c. A t with no matching rows passes automatically (“vacuously true”).
    • A conjunct like $\exists z \in R\,(t[P] = z[P])$ with $t \in R$ is always true (take z = t): it filters nothing.

    The widget uses Player from Part 1 and this Score table (a player can have several innings; P6 has none yet):

    Score
    pidmatchruns
    P1m172
    P1m28
    P2m115
    P3m151
    P3m249
    P4m23
    P5m10
    Try it

    Test each Player tuple t against the formula. The Score rows that belong to t light up green (satisfy the inner condition) or red (don’t). Compare ∃ with ∀: P1 passes “some score above 50” but fails “every score at least 10”, and Sana (P6), with no scores at all, passes the ∀ query vacuously.

    GATE DA 2026 · Q59 · NAT · 2 marks

    Let there be two relations $X$ and $Y$ as shown. $X$ has three columns $P$, $Q$ and $R$. $Y$ has two columns $P$ and $S$.

    X
    PQR
    P1Q1R1
    P2Q2R2
    P3Q3R2
    Y
    PS
    P110
    P115
    P220
    P31

    Consider that the following tuple relational calculus expression is evaluated.

    $$\{t \mid t \in X \wedge \exists z \in X\,(t[P] = z[P]) \wedge \exists m \in Y\,(m[P] = t[P] \wedge m[S] \gt 1)\}$$

    The number of tuples that will be returned is __________ . (Answer in integer)

    1. The candidates are the three rows of X. The middle conjunct $\exists z \in X\,(t[P] = z[P])$ is true for every t (choose z = t), so it removes nothing.

      Spot always-true conjuncts first; they are there to distract.

    2. Test the last conjunct for each t. P1: Y has (P1, 10) with 10 > 1, true. P2: (P2, 20), true. P3: its only Y row is (P3, 1), and 1 > 1 is false.

      ∃ needs just one witness; P1’s two Y rows don’t make it appear twice.

    3. The result is the X tuples for P1 and P2: 2 tuples.

      Official key: 2 to 3 (both values were accepted); evaluating the expression as printed gives 2.

    Using Player (Part 1) and Score (above), how many tuples does $\{t \mid t \in \text{Player} \wedge \forall s \in \text{Score}\,(s[pid] = t[pid] \Rightarrow s[runs] \ge 10)\}$ return?

    For each player, check every Score row of theirs. A player with no Score rows satisfies the ∀ automatically.

    P1 fails (8), P2 passes (15), P3 passes (51, 49), P4 fails (3), P5 fails (0), P6 passes vacuously (no rows). 3 tuples.

    How many tuples does $\{t \mid t \in \text{Score} \wedge \exists u \in \text{Score}\,(u[pid] = t[pid] \wedge u[match] \ne t[match])\}$ return?

    Keep a Score row if the same player has another row with a different match.

    Only P1 and P3 have two matches each, so their 4 rows qualify. Everyone else has a single row and no other match to point to.

    The query $\{t \mid t \in \text{Player} \wedge \neg\exists s \in \text{Score}\,(s[pid] = t[pid])\}$ returns players with no innings. Which algebra expression gives exactly their pid values?

    “No matching row” is a set difference.

    π pid(Player) − π pid(Score): every player’s pid, minus those that appear in Score (P6 here). The join and the intersection give the players who do have scores.

    Which of these TRC expressions is unsafe? (i) $\{t \mid t \in \text{Player} \wedge t[team] = \text{'KK'}\}$   (ii) $\{t \mid \neg(t \in \text{Player})\}$   (iii) $\{t \mid t \in \text{Player} \wedge \neg\exists s \in \text{Score}\,(s[pid] = t[pid])\}$

    Unsafe means the answer could be infinite or use values from outside the database.

    (ii) asks for every possible tuple that is not a player: infinitely many. (i) and (iii) start with t ∈ Player, which keeps t inside a finite table.

    Using Player (Part 1) and Score (above), how many tuples does this query return?

    $$\{t \mid t \in \text{Player} \wedge \forall s \in \text{Score}\,\big(s[pid] = t[pid] \Rightarrow \exists u \in \text{Score}\,(u[match] = s[match] \wedge u[runs] \gt s[runs])\big)\}$$

    Read the inner part first: “someone scored more than innings s in the same match”. So a player qualifies when none of their innings was the top score of its match. Think about players with no innings at all.

    Top score in each match: m1 has 72 (P1), 15, 51 and 0, so P1 tops it; m2 has 8, 49 (P3) and 3, so P3 tops it.

    P1 fails (72 is the top of m1). P2 passes (15 is beaten). P3 fails (49 tops m2), even though its 51 in m1 was beaten: ∀ needs every innings to be beaten. P4 passes (3 is beaten). P5 passes (0 is beaten).

    P6 has no Score rows, so the implication is never tested and the ∀ is vacuously true: P6 passes.

    Result: P2, P4, P5, P6, so 4 tuples. Forgetting the vacuous case gives 3.

    Relations: Player(pid, name), Ground(gid, city) and Plays(pid, gid). Ground has at least one row. What does this query return?

    $$\{t \mid t \in \text{Player} \wedge \exists g \in \text{Ground}\;\forall p \in \text{Plays}\,\big(p[pid] = t[pid] \Rightarrow p[gid] = g[gid]\big)\}$$
    1. Players who have played at every ground
    2. Players who have played at exactly one ground
    3. Players who have played at no more than one ground, including players who haven’t played at all
    4. Players who have played at some ground

    Fix a ground g and read the ∀ part on its own: what does it say about t’s Plays rows? Then ask what the ∃ in front adds, and what happens for a player with no Plays rows.

    For a fixed g, the ∀ part says every Plays row of t is at ground g. The ∃g in front says one single ground covers all of t’s rows, so t has played at most at one distinct ground.

    A player with no Plays rows makes the implication vacuously true for every g, and since Ground isn’t empty such a g exists. So those players are included too. Answer (C).

    (A) is what you get with the quantifiers the other way round, $\forall g\,\exists p$ (division). (B) misses the players with no rows. (D) would be $\exists p$ alone.

    R
    AB
    1x
    1y
    2x
    3z
    4x
    4y
    4z
    S
    B
    x
    y

    How many tuples does each query return? In $Q_2$, t has the single attribute A.

    $$Q_1 = \{t \mid t \in R \wedge \exists s \in S\,(s[B] = t[B])\}$$$$Q_2 = \{t \mid \exists u \in R\,(u[A] = t[A]) \wedge \forall s \in S\;\exists v \in R\,(v[A] = t[A] \wedge v[B] = s[B])\}$$

    $Q_1$ keeps whole rows of R; ∃ only asks whether a witness exists. $Q_2$ works on A values: for each A in R, does R pair it with every B in S? Which algebra operator is that?

    $Q_1$: keep the rows of R whose B is x or y: (1, x), (1, y), (2, x), (4, x), (4, y), so 5 tuples. Each row appears once, whatever the number of matches.

    $Q_2$ is the division $R \div S$. The candidates are A = 1, 2, 3, 4. 1 has x and y ✓; 2 has only x ✗; 3 has only z ✗; 4 has x, y and z ✓ (the extra z doesn’t matter). So 2 tuples.

    If t has three matching S rows that satisfy c, how many times does t appear in $\{t \mid t \in R \wedge \exists s \in S\,(\ldots)\}$?

    three
    That would be a join, which pairs t with each match.
    once
    The result is a set of R’s tuples; ∃ only asks whether a witness exists.
    zero
    One witness is enough.

    Safe tuple relational calculus is

    strictly more powerful than relational algebra
    Every safe TRC query has an algebra equivalent.
    equally powerful as relational algebra
    Codd’s theorem: they express the same queries.
    less powerful, since it has no division
    ∀ provides what division does.

    |R| = 5 and |S| = 4. The largest possible |R ⋈ S| is

    5
    One R row can match several S rows.
    9
    Join sizes multiply, they don’t add.
    20
    At most |R| · |S|, reached when every pair matches.

    R ∩ S can be written using only difference as

    R − S
    That’s what’s in R but not S.
    R − (R − S)
    Remove from R the part not in S; what remains is in both.
    (R − S) − S
    That still equals R − S.

    Which TRC query matches the algebra σruns > 50(Score)?

    { t | t ∈ Score ∧ t[runs] > 50 }
    A selection is a condition on t itself.
    { t | ∃s ∈ Score (s[runs] > 50) }
    t isn’t tied to any table here: unsafe.
    { t | t ∈ Score ∧ ∀s ∈ Score (s[runs] > 50) }
    That demands every score exceed 50.

    Joining Player and Team on the foreign key team, with every player’s team present in Team, returns how many rows if Player has 6 rows?

    5
    Each player matches exactly one team.
    6
    Team.team is a key, so each player row meets exactly one team row.
    30
    That’s the Cartesian product.

    SQL is the language real databases speak, and GATE DA asks at least one SQL question every year, usually “how many rows does this return?”. This part covers SELECT–FROM–WHERE, joins, aggregates with GROUP BY and HAVING, NULLs, and then nested and correlated subqueries, the source of the trickiest 2-mark questions.

    You need: Parts 1–2 (keys, joins, selection and projection).

    SQL queries: SELECT, joins, GROUP BY and NULL

    An SQL query names the tables to combine (FROM), the rows to keep (WHERE), how to group them (GROUP BY), which groups to keep (HAVING) and what to output (SELECT).

    GATE asks you to run a query in your head on a small table and count the rows (2024 Q31), or to decide which of several queries produces a given output (2026 Q51). Both are easy once you know the order in which the clauses are evaluated.

    It’s like a scorer’s season report: take the scorecards (FROM), throw out abandoned matches (WHERE), sort them into one pile per team (GROUP BY), drop teams with too few games (HAVING), and write one line per team (SELECT).

    Where it shows up in GATE DA

    Count the rows a query returns; pick the query that produces a given table.

    2024 Q31 · join with conditions, count rows2026 Q51 · GROUP BY in a derived table2024 Q55 · which indexes speed up a query (Part 5)
    Heat: every year, 1–2 marks
    1. FROM (and joins): build the combined table. A comma between tables is a Cartesian product.
    2. WHERE: keep the rows whose condition is true (not false, not unknown). Works on single rows; no aggregates allowed.
    3. GROUP BY: split the surviving rows into groups with equal grouping values.
    4. HAVING: keep the groups whose condition is true. May use aggregates.
    5. SELECT: compute the output columns (one row per group if grouped). DISTINCT removes duplicate output rows.
    6. ORDER BY: sort the output. It never changes the number of rows.

    Unlike relational algebra, SQL keeps duplicate rows unless you write DISTINCT. With GROUP BY, every column in SELECT must be grouped or inside an aggregate.

    • A JOIN B ON cond (inner join) = the rows of A × B satisfying cond. NATURAL JOIN matches all same-named columns.
    • Outer joins also keep unmatched rows, padding the other side with NULLs: LEFT keeps every row of A, RIGHT every row of B, FULL both.
    • Aggregates: COUNT(*) counts rows; COUNT(col), SUM, AVG, MIN, MAX ignore NULLs. COUNT(DISTINCT col) counts distinct non-NULL values.
    • Three-valued logic: any comparison with NULL (even NULL = NULL) is UNKNOWN. WHERE and HAVING keep only TRUE rows. Test for NULL with IS NULL / IS NOT NULL.
    • Set operations UNION, INTERSECT, EXCEPT remove duplicates (add ALL to keep them).

    The widget and the practice use this version of the league’s Player table, with runs for the season. Sana’s runs haven’t been entered yet, so they’re NULL.

    Player
    pidnameteamroleruns
    P1AaravKKBatter412
    P2DiyaKKBowler88
    P3KabirHHBatter365
    P4MeeraBBAll-rounder240
    P5RohanNNBatter455
    P6SanaBBBowlerNULL
    P7IshaHHBowler45
    P8VikramKKAll-rounder301
    Try it

    Step a query through FROM, WHERE, GROUP BY, HAVING and SELECT, and watch the table shrink. In “NULLs in aggregates”, compare COUNT(*) with COUNT(runs) for BB. In “WHERE + HAVING”, notice that WHERE removes rows before grouping while HAVING removes whole groups after.

    GATE DA 2024 · Q31 · NAT · 1 mark

    Consider the following two tables named Raider and Team in a relational database maintained by a Kabaddi league. The attribute ID in table Team references the primary key of the Raider table, ID.

    Raider
    IDNameRaidsRaidPoints
    1Arjun200250
    2Ankush190219
    3Sunil150200
    4Reza150190
    5Pratham175220
    6Gopal193215
    Team
    CityIDBidPoints
    Jaipur2200
    Patna3195
    Hyderabad5175
    Jaipur1250
    Patna4200
    Jaipur6200

    The SQL query described below is executed on this database:

    SELECT *
    FROM Raider, Team
    WHERE Raider.ID=Team.ID AND City=“Jaipur” AND
    RaidPoints > 200;

    The number of rows returned by this query is ______.

    1. Raider.ID = Team.ID turns the product into a join: each Team row meets its one raider (ID is Raider’s key).

      So the join has exactly 6 rows, one per Team row.

    2. City = 'Jaipur' keeps the Team rows with IDs 2, 1 and 6.

      Filter the smaller table first.

    3. Their RaidPoints are 219, 250 and 215, all > 200. Answer 3 rows.

      Check strictness: Sunil’s 200 would fail “> 200”, but he plays for Patna anyway. Official key: 3.

    GATE DA 2026 · Q51 · MSQ · 2 marks

    Consider a table Employee(EmpID, TeamID), where the column EmpID (ID of an employee) is the primary key. The column TeamID denotes the team ID of the team of which the employee is a member. TeamID is a NOT NULL column. We want to display the size of the team (denoted as TeamSize) in which each employee is a member by using SQL. As an example, the desired output for the given Employee table is also shown in tabular form. Which of the following is/are correct?

    Employee
    EmpIDTeamID
    18
    28
    38
    47
    57
    69
    Output
    EmpIDTeamSize
    13
    23
    33
    42
    52
    61
    1. SELECT E.EmpID, B.TeamSize
      FROM Employee AS E, (SELECT TeamID, COUNT(TeamID) AS
      TeamSize FROM Employee GROUP BY TeamID) AS B
      WHERE E.TeamID = B.TeamID
    2. SELECT A.EmpID, COUNT(B.TeamID) AS TeamSize
      FROM Employee AS A, Employee AS B
      WHERE A.TeamID = B.TeamID AND A.EmpID = B.EmpID
      GROUP BY A.EmpID
    3. SELECT B.EmpID, B.TeamSize
      FROM (SELECT EmpID, COUNT(TeamID) AS TeamSize
      FROM Employee GROUP BY EmpID) AS B
    4. SELECT A.EmpID, B.TeamSize
      FROM Employee AS A, (SELECT COUNT(TeamID) AS TeamSize FROM
      Employee GROUP BY TeamID) AS B
      WHERE A.TeamID = B.TeamID

    Run each one: what does each group contain? In (D), which columns does the derived table B actually have?

    (A) B holds (8, 3), (7, 2), (9, 1); joining on TeamID gives each employee their team’s size ✓. (B) The extra condition A.EmpID = B.EmpID pairs each employee only with themselves, so every count is 1 ✗. (C) Grouping by the key EmpID makes one-row groups: every TeamSize is 1 ✗. (D) B has only the column TeamSize, so B.TeamID doesn’t exist and the query is an error ✗. Answer: A. Official key: A. (All four were run in SQLite.)

    On the Player table above, how many rows does this return?

    SELECT team, AVG(runs) FROM Player
    GROUP BY team HAVING AVG(runs) > 250;

    Compute each team’s average, ignoring NULLs.

    KK: (412 + 88 + 301)/3 = 267; HH: (365 + 45)/2 = 205; BB: 240 (Sana’s NULL is ignored, so it’s 240/1); NN: 455. Above 250: KK and NN, so 2 rows.

    Team has the 5 teams KK, HH, BB, NN, HY. How many rows does SELECT * FROM Team T LEFT OUTER JOIN Player P ON T.team = P.team; return, with the Player table above?

    Each matched pair is one row; an unmatched Team row still appears once, padded with NULLs.

    KK 3 + HH 2 + BB 2 + NN 1 = 8 matched rows, plus HY (no players) once with NULLs: 9.

    What does SELECT COUNT(*) FROM Player WHERE runs > 100 OR runs <= 100; return on the Player table above?

    For Sana, both comparisons involve NULL.

    The condition looks always true, but for Sana it is UNKNOWN OR UNKNOWN = UNKNOWN, so her row is dropped: 7.

    Besides the Player table above, the league keeps an Award table. P1’s 2026 amount hasn’t been decided yet.

    Award
    pidseasonamount
    P1202550
    P12026NULL
    P3202630
    P5202540
    P5202660
    P8202620

    How many rows does this query return?

    SELECT P.team
    FROM Player P LEFT JOIN Award A ON P.pid = A.pid
    GROUP BY P.team
    HAVING COUNT(*) > COUNT(A.amount);

    Build the left join team by team: a player with no award still appears once, with NULLs. Then compare COUNT(*), which counts rows, with COUNT(A.amount), which skips NULLs.

    Rows of the left join, per team:

    • KK: P1 twice (50 and NULL), P2 unmatched (NULL), P8 (20). COUNT(*) = 4, COUNT(amount) = 2 ✓.
    • HH: P3 (30), P7 unmatched. 2 against 1 ✓.
    • BB: P4 and P6 both unmatched. 2 against 0 ✓.
    • NN: P5 twice (40, 60). 2 against 2 ✗.

    So KK, HH and BB qualify: 3 rows. With an inner JOIN only KK would qualify (because of P1’s NULL amount), giving 1.

    Team holds the 5 teams KK, HH, BB, NN, HY, and Player is the table above. What do these two queries return?

    Q1: SELECT COUNT(*) FROM Team T LEFT JOIN Player P
        ON T.team = P.team AND P.runs > 300;
    Q2: SELECT COUNT(*) FROM Team T LEFT JOIN Player P
        ON T.team = P.team WHERE P.runs > 300;
    1. 6 and 6
    2. 4 and 4
    3. 6 and 4
    4. 9 and 4

    A condition in ON decides which pairs match; a team with no match is still kept once, padded with NULLs. A condition in WHERE runs after the join and removes rows, including padded ones.

    Players with runs above 300: P1 (KK, 412), P8 (KK, 301), P3 (HH, 365), P5 (NN, 455).

    Q1: KK matches 2 players, HH 1, NN 1. BB has no player above 300 (240 and NULL), so it appears once with NULLs, and so does HY. Total 2 + 1 + 1 + 1 + 1 = 6.

    Q2: the join itself has 9 rows (8 players plus HY padded). WHERE keeps only rows where P.runs > 300 is TRUE; the padded rows have P.runs NULL, which gives UNKNOWN. That leaves the 4 rows above.

    Answer (C). (D) uses 9, the left join with no runs condition at all.

    On the 8-row Player table above, which of the following is/are correct?

    1. SELECT COUNT(*) - COUNT(runs) FROM Player; returns 1.
    2. SELECT team FROM Player GROUP BY team HAVING MIN(runs) > 50; returns 2 rows.
    3. SELECT team FROM Player WHERE role = 'Batter' UNION SELECT team FROM Player WHERE runs < 100; returns 5 rows.
    4. SELECT SUM(runs) / COUNT(*) FROM Player WHERE team = 'BB'; returns 120.

    Sana’s runs are NULL. Ask of each aggregate whether it skips NULLs, and of each set operation whether it keeps duplicates.

    (A) True. COUNT(*) = 8 and COUNT(runs) = 7 (Sana’s NULL is skipped), so the difference is 1.

    (B) False. MIN skips NULL. KK’s minimum is 88, HH’s 45, BB’s 240 (Sana ignored) and NN’s 455, so KK, BB and NN qualify: 3 rows.

    (C) False. Batters’ teams are KK, HH, NN and players under 100 runs are in KK, HH. UNION removes duplicates, giving 3 rows. Only UNION ALL returns 5.

    (D) True. SUM(runs) for BB is 240 (NULL skipped) but COUNT(*) is 2, so the result is 120. AVG(runs) would give 240.

    Correct: A, D.

    • Evaluate in the order FROM → WHERE → GROUP BY → HAVING → SELECT.
    • Treat a comma in FROM plus an equality in WHERE as a join on that equality.
    • Check every NULL: it fails WHERE conditions and is skipped by aggregates other than COUNT(*).
    • Putting an aggregate in WHERE (it belongs in HAVING).
    • Assuming SQL removes duplicates the way π does.
    • Writing = NULL instead of IS NULL.
    1. Clauses run as FROM → WHERE → GROUP BY → HAVING → SELECT → ORDER BY; WHERE filters rows, HAVING filters groups.
    2. COUNT(*) counts rows; COUNT(col), SUM, AVG, MIN and MAX ignore NULLs.
    3. Comparisons with NULL are UNKNOWN, and only TRUE rows survive WHERE and HAVING; outer joins keep unmatched rows with NULLs.

    Which clause can filter on COUNT(*) > 2?

    WHERE
    WHERE runs before grouping, when there’s no count yet.
    HAVING
    HAVING runs after grouping, so it can use aggregates.
    ORDER BY
    ORDER BY sorts; it never removes rows.

    A column has values 4, NULL, 8. AVG of the column is

    4
    That treats NULL as 0: (4 + 0 + 8)/3.
    6
    NULL is skipped: (4 + 8)/2.
    NULL
    AVG returns NULL only if every value is NULL.

    SELECT team FROM Player; on the 8-row table returns

    4 rows
    That needs DISTINCT.
    8 rows
    SQL keeps duplicates by default.
    5 rows
    HY has no players, and duplicates aren’t removed anyway.

    Subqueries: nested, correlated, EXISTS and NOT IN

    A subquery is a query inside another query. If it mentions a column of the outer query it is correlated and must be re-evaluated for every outer row; otherwise it is computed once.

    GATE’s 2-mark SQL questions are built on this: count the accounts that have at least as many richer accounts as poorer ones (2026 Q60), or decide what a NOT EXISTS query returns (sample paper Q55).

    It’s like a selector checking each player against their own team’s average. The benchmark changes with every player, so you recompute it each time. A fixed benchmark, like “better than the league’s best wicketkeeper”, is computed once.

    Where it shows up in GATE DA

    Count the rows; interpret EXISTS and NOT EXISTS.

    2026 Q60 · correlated COUNT subqueries2025 Q33 · comparison with a MAX subquerySample Q55 · NOT EXISTS means “all”
    Heat: every year, 1–2 marks
    • Scalar subquery: returns one value, used in a comparison: WHERE runs > (SELECT AVG(runs) FROM Player).
    • x IN (subquery): x equals some returned value. x NOT IN (…): x differs from all of them.
    • x > ANY (…) (also SOME): greater than at least one value. x > ALL (…): greater than every value (true if the subquery is empty).
    • EXISTS (…): the subquery returns at least one row. NOT EXISTS (…): it returns none.
    • Correlated: the inner query refers to the outer row (e.g. WHERE Q.team = P.team). Evaluate it once per outer row.
    • “For all” via NOT EXISTS: WHERE NOT EXISTS (SELECT … WHERE <belongs to outer row> AND NOT <condition>) means every related row satisfies the condition (vacuously true when there are no related rows). It’s SQL’s division.
    • NOT IN with NULL: if the subquery returns even one NULL, x NOT IN (…) can never be TRUE (x ≠ NULL is UNKNOWN), so the query returns no rows. NOT EXISTS doesn’t have this trap.
    Try it

    Evaluate each outer row in turn: the purple columns show what the subquery returns for that row. Compare 2025 Q33, where the inner value is the same every time (not correlated), with 2026 Q60 and “above team average”, where it changes row by row. In the team-average query, see what happens to Sana’s NULL.

    GATE DA 2026 · Q60 · NAT · 2 marks

    Let Account be a relation as shown.

    Account
    AccNoBalance
    A15000
    A25000
    A310000
    A415000
    A518000

    Consider the given SQL query.

    SELECT AccNo FROM Account AS A
    WHERE (SELECT COUNT(*) FROM Account AS B
    WHERE A.Balance < B.Balance) >= (SELECT COUNT(*)
    FROM Account AS C WHERE A.Balance > C.Balance)

    The number of rows returned by the SQL query is __________ . (Answer in integer)

    1. For each account A, the first subquery counts accounts with a strictly larger balance (“richer”), the second counts accounts with a strictly smaller balance (“poorer”). Both mention A, so both are correlated.

      Put the meaning into words before computing.

    2. A1 (5000): richer 3, poorer 0, and 3 ≥ 0 ✓. A2 (5000): same, ✓. A3 (10000): richer 2, poorer 2, and 2 ≥ 2 ✓. A4 (15000): richer 1, poorer 3 ✗. A5 (18000): richer 0, poorer 4 ✗.

      Ties count as neither richer nor poorer, because both comparisons are strict.

    3. Three accounts qualify: 3.

      Official key: 3.

    GATE DA 2025 · Q33 · NAT · 1 mark

    On a relation named Loan of a bank:

    Loan
    loan numberbranch nameamount
    L11Banjara Hills90000
    L14Kondapur50000
    L15SR Nagar40000
    L22SR Nagar25000
    L23Balanagar80000
    L25Kondapur70000
    L19SR Nagar65000

    the following SQL query is executed.

    SELECT L1.loan number
    FROM Loan L1
    WHERE L1.amount > (SELECT MAX (L2.amount)
                       FROM Loan L2
                       WHERE L2.branch name = ’SR Nagar’);

    The number of rows returned by the query is ______ (Answer in integer)

    The subquery doesn’t mention L1, so compute it once.

    The largest SR Nagar loan is 65000. Loans above it: 90000, 80000, 70000, so 3 rows. Official key: 3.

    GATE DA 2024 sample paper · Q55 · MCQ · 2 marks

    Consider the following relational schema: employee(empId, empName, empDept), customer(custId, custName, salesRepId, rating). salesRepId is a foreign key referring to empId of the employee relation. Assume that each employee makes a sale to at least one customer. What does the following query return?

    SELECT empName
    FROM employee E
    WHERE NOT EXISTS (SELECT custId
                      FROM customer C
                      WHERE C.salesRepId = E.empId
                      AND C.rating <> ’GOOD’);
    1. Names of all the employees with at least one of their customers having a ‘GOOD’ rating.
    2. Names of all the employees with at most one of their customers having a ‘GOOD’ rating.
    3. Names of all the employees with none of their customers having a ‘GOOD’ rating.
    4. Names of all the employees with all their customers having a ‘GOOD’ rating.

    The subquery finds this employee’s customers who are not rated GOOD. When is that set empty?

    NOT EXISTS (a customer of E not rated GOOD) = every customer of E is rated GOOD: (D). The assumption that each employee has at least one customer rules out the vacuous case. (Sample paper, no official key.)

    On the Player table from Ch. 3.1, how many names does this return?

    SELECT name FROM Player P
    WHERE runs > (SELECT AVG(runs) FROM Player Q
                  WHERE Q.team = P.team);

    Team averages (ignoring NULL): KK 267, HH 205, BB 240, NN 455. Use strict “>”.

    KK: Aarav 412 ✓, Diya ✗, Vikram 301 ✓. HH: Kabir 365 ✓, Isha ✗. BB: Meera 240 is not > 240 ✗; Sana NULL gives UNKNOWN ✗. NN: Rohan 455 = average ✗. So 3 names.

    On the same table, how many rows does SELECT name FROM Player WHERE runs > ALL (SELECT runs FROM Player WHERE team = 'HH'); return?

    HH’s runs are 365 and 45. “> ALL” means bigger than both.

    Runs above 365: Aarav (412) and Rohan (455), so 2. (With > ANY, anyone above 45 would qualify.)

    On the Player table from Ch. 3.1, how many names does this query return?

    SELECT name FROM Player P
    WHERE 2 > (SELECT COUNT(*) FROM Player Q
               WHERE Q.runs > P.runs);

    For each player, the subquery counts the players with strictly more runs. Most players are easy; think hard about the one whose runs are NULL. What does the inner WHERE do for her?

    The query keeps players with fewer than 2 players above them. Sorted runs: 455 (Rohan), 412 (Aarav), 365, 301, 240, 88, 45, and Sana’s NULL.

    Rohan: 0 above ✓. Aarav: 1 above ✓. Kabir: 2 above ✗, and everyone lower has even more.

    Sana: every comparison Q.runs > NULL is UNKNOWN, so the inner WHERE keeps no rows and COUNT(*) returns 0. Then 2 > 0 is TRUE, and she is returned.

    Result: Rohan, Aarav and Sana, so 3. The tempting answer 2 assumes a NULL comparison makes the whole outer condition UNKNOWN; but COUNT never returns NULL.

    Team holds KK, HH, BB, NN and HY. A Transfer table lists pending moves; P4’s destination isn’t known yet.

    Transfer
    pidto_team
    P2HH
    P4NULL
    P7KK
    Q1: SELECT team FROM Team
        WHERE team NOT IN (SELECT to_team FROM Transfer);
    Q2: SELECT team FROM Team T
        WHERE NOT EXISTS (SELECT * FROM Transfer X
                          WHERE X.to_team = T.team);
    Q3: SELECT team FROM Team
        WHERE team IN (SELECT to_team FROM Transfer);

    The numbers of rows returned by Q1, Q2 and Q3 are, in that order,

    1. 3, 3 and 2
    2. 0, 3 and 2
    3. 0, 0 and 2
    4. 0, 3 and 3

    The subquery returns HH, NULL and KK. Write x NOT IN (HH, NULL, KK) as three ≠ comparisons joined by AND, and work out its truth value for a team like BB.

    Q1: for BB, the condition is (BB ≠ HH) AND (BB ≠ NULL) AND (BB ≠ KK) = TRUE AND UNKNOWN AND TRUE = UNKNOWN. For HH and KK it is FALSE. No team gets TRUE, so 0 rows.

    Q2: NOT EXISTS checks each team for a matching row. The NULL row matches nothing, so BB, NN and HY have no match: 3 rows.

    Q3: IN is TRUE as soon as one comparison is TRUE: HH and KK, 2 rows. For the others it’s UNKNOWN, which also drops them.

    Answer (B). (A) ignores the NULL, (C) wrongly applies the NULL trap to NOT EXISTS, and (D) treats IN as if NULL matched the other teams.

    On the Player table from Ch. 3.1, which of the following is/are correct?

    1. SELECT COUNT(*) FROM Player WHERE runs > ANY (SELECT runs FROM Player WHERE team = 'KK'); returns 5.
    2. SELECT name FROM Player WHERE runs >= ALL (SELECT runs FROM Player); returns only Rohan.
    3. SELECT name FROM Player P WHERE NOT EXISTS (SELECT * FROM Player Q WHERE Q.team = P.team AND Q.runs > P.runs); returns 5 names.
    4. Replacing the NOT EXISTS condition in (C) by runs >= ALL (SELECT runs FROM Player Q WHERE Q.team = P.team) returns the same 5 names.

    > ANY needs one TRUE comparison; >= ALL needs every comparison TRUE, and a single UNKNOWN spoils it. NOT EXISTS only asks whether the inner query returns a row.

    (A) True. KK’s runs are 88, 412 and 301, so > ANY means more than 88: 412, 365, 240, 455 and 301, which is 5 players. (Diya’s 88 isn’t more than 88, and Sana’s NULL gives UNKNOWN.)

    (B) False. The subquery contains Sana’s NULL, so for Rohan, 455 >= NULL is UNKNOWN and the ALL condition can’t be TRUE. The query returns no rows.

    (C) True. It keeps players with no teammate scoring more: Aarav (KK), Kabir (HH), Rohan (NN), and both BB players. For Meera, Sana’s NULL > 240 is UNKNOWN, so no row comes back; for Sana, 240 > NULL is UNKNOWN too. 5 names.

    (D) False. For BB the subquery returns 240 and NULL, so neither Meera nor Sana gets TRUE from >= ALL. Only Aarav, Kabir and Rohan remain: 3 names.

    Correct: A, C.

    • Ask first: does the subquery mention an outer table? If not, compute it once.
    • Rewrite NOT EXISTS (… AND NOT c) as “all related rows satisfy c”.
    • For each outer row, write the inner value next to it, as in the widget.
    • Using NOT IN on a column that may contain NULL.
    • Ignoring ties when the comparison is strict.
    • Confusing > ANY (beats the smallest) with > ALL (beats the largest).
    1. A correlated subquery refers to the outer row and is re-run for each one; an uncorrelated one is computed once.
    2. EXISTS tests for at least one row; NOT EXISTS (… AND NOT c) expresses “for all”, SQL’s division.
    3. > ALL beats every value, > ANY beats at least one; NOT IN fails when the subquery returns a NULL.

    x > ALL (empty subquery) is

    false
    There’s no value for x to fail against.
    true
    Vacuously true: x beats every one of zero values.
    UNKNOWN
    UNKNOWN comes from NULLs, not from an empty set.

    Player.team contains a NULL. SELECT team FROM Team WHERE team NOT IN (SELECT team FROM Player) returns

    HY only
    That’s what NOT EXISTS would return.
    no rows
    “HY ≠ NULL” is UNKNOWN, so NOT IN is never TRUE. (Checked in SQLite.)
    every team
    Teams with players fail NOT IN regardless of the NULL.

    A query with a correlated subquery and 1000 outer rows evaluates the subquery (conceptually)

    once
    That’s the uncorrelated case.
    1000 times
    Once per outer row, since its result depends on the row.
    twice
    Its value can change with every outer row.

    SELECT COUNT(DISTINCT team) FROM Player; on the Ch. 3.1 table returns

    8
    That’s COUNT(*).
    4
    KK, HH, BB and NN.
    5
    HY isn’t in Player.

    Which SQL expresses Plays ÷ Ground (“players who played at every ground”)?

    a single join of Plays and Ground
    A join lists pairs; it can’t say “every”.
    a doubly nested NOT EXISTS
    “No ground exists that this player hasn’t played at.”
    GROUP BY pid alone
    You’d still need to compare each player’s count with the number of grounds.

    FROM R, S WHERE R.a = S.a is equivalent in relational algebra to

    R × S
    The WHERE condition filters the product.
    σR.a = S.a(R × S), a theta join
    A product followed by a selection (both copies of a are kept).
    R ∪ S
    Union stacks rows; it doesn’t pair them.

    Joining each Player row to Team on the foreign key with an INNER JOIN drops

    nothing, ever
    Rows with a NULL foreign key find no match.
    players whose team is NULL
    NULL matches nothing; a LEFT JOIN would keep them.
    teams that have players
    Those are exactly the ones that match.

    Design theory: how to tell whether a table is well designed. A functional dependency says one set of columns determines another; from a list of them you can find every key, and from the keys you can decide the normal form (1NF, 2NF, 3NF, BCNF) and how to split a badly designed table without losing information. GATE asks one or two of these every year.

    You need: Part 1 (superkeys, candidate keys, prime attributes) and Part 2 (natural join, projection).

    Functional dependencies, closure and finding every key

    A functional dependency X → Y says: any two rows that agree on X also agree on Y. The closure X⁺ is everything X determines, and X is a superkey exactly when X⁺ contains every attribute.

    GATE asks you to find candidate keys (2026 Q17, 2025 Q57), to decide which dependencies follow from a given set (2024 Q46) and to count superkeys (sample Q41). One algorithm, attribute closure, answers all of them.

    It’s like a team sheet: knowing the player ID tells you the player’s name and team, and knowing the team tells you its home city. So the player ID determines the city too, without being told directly.

    Where it shows up in GATE DA

    Candidate keys from FDs; implied FDs; counting superkeys.

    2026 Q17 · the candidate keys of R(A,B,C,D,E)2025 Q57 · candidate keys and BCNF2024 Q46 · which FDs can be derivedSample Q41 · number of superkeys
    Heat: every year, 1–2 marks
    • $X \to Y$ holds in R if any two tuples that agree on all of X also agree on all of Y. In Player(pid, name, team, city): pid → name, team and team → city.
    • An FD is trivial if $Y \subseteq X$ (like AB → A); it always holds.
    • The closure $X^+$ is the set of all attributes determined by X. X is a superkey of R exactly when $X^+$ is all of R.
    • One table of data can show that an FD fails (two rows agree on X but differ on Y), but it can never prove an FD holds for all future data; FDs come from the meaning of the data.
    • Reflexivity: if $Y \subseteq X$ then $X \to Y$.
    • Augmentation: if $X \to Y$ then $XZ \to YZ$.
    • Transitivity: if $X \to Y$ and $Y \to Z$ then $X \to Z$.
    • Derived rules: union ($X \to Y$, $X \to Z$ give $X \to YZ$), decomposition ($X \to YZ$ gives $X \to Y$), pseudo-transitivity ($X \to Y$, $WY \to Z$ give $WX \to Z$).
    • In practice: $X \to Y$ follows from F exactly when $Y \subseteq X^+$ (computed with F).
    1. Start with result = X.
    2. Repeat: for each FD $L \to R$ in F, if $L \subseteq$ result, add R to result.
    3. Stop when a full pass adds nothing. Then result = $X^+$.
    • An attribute that appears on no right-hand side can’t be derived, so it is in every key. Start with the set N of such attributes and compute N⁺.
    • If N⁺ is everything, N is the only key. Otherwise, add one attribute at a time (then two…) and keep the minimal sets whose closure is everything.
    • Attributes that appear only on right-hand sides are in no key.
    • Number of superkeys with a single key K of size k in n attributes: $2^{n-k}$. With several keys, use inclusion–exclusion.
    Try it

    Load a GATE question’s dependencies and close any attribute set; the trace lists each FD as it fires. The readout also lists the attributes that must be in every key, all candidate keys and the number of superkeys. Edit the FDs to experiment: for instance, delete E → A from the 2026 Q17 set and watch the keys change.

    GATE DA 2026 · Q17 · MCQ · 1 mark

    Let R(A,B,C,D,E) be a relational schema with functional dependency set F={A→BC, CD→E, E→A}. Which of the following statements is correct?

    1. AD, ED and CD are the only candidate keys of R.
    2. AD and ED are the only candidate keys of R.
    3. A, E and CD are the only candidate keys of R.
    4. A and CD are the only candidate keys of R.
    1. The right-hand sides contain B, C, E, A, but never D. So D is in every key, which rules out (C) and (D) immediately (A alone has no D).

      The “never on the right” test is the fastest filter.

    2. D⁺ = {D}: not a key. Try D with one more attribute. AD⁺: A → BC gives ABCD, then CD → E gives ABCDE ✓. CD⁺: CD → E, E → A, A → BC gives ABCDE ✓. ED⁺: E → A, A → BC, giving ABCDE ✓. BD⁺ = {B, D} ✗.

      Each is a superkey, and it’s minimal because D alone isn’t one and the other attribute alone lacks D.

    3. Any other key would have to contain D plus attributes outside {A, C, E}, i.e. B; but BD isn’t a key, and larger sets containing A, C or E aren’t minimal. So the keys are exactly AD, ED and CD: (A).

      Option (B) misses CD, the key reached through E. Official key: (A).

    GATE DA 2024 · Q46 · MSQ · 2 marks

    Given the relational schema $R = (U, V, W, X, Y, Z)$ and the set of functional dependencies: $\{U \to V, U \to W, WX \to Y, WX \to Z, V \to X\}$. Which of the following functional dependencies can be derived from the above set?

    1. $VW \to YZ$
    2. $WX \to YZ$
    3. $VW \to U$
    4. $VW \to Y$

    Compute VW⁺ and WX⁺, then check whether each right-hand side is inside.

    VW⁺: V → X gives VWX; WX → Y, Z gives VWXYZ. U is never derived (no FD has U on its right). WX⁺ = WXYZ. So (A) ✓, (B) ✓ (union rule), (C) ✗, (D) ✓. Official key: A; B; D.

    GATE DA 2025 · Q57 · MSQ · 2 marks

    Consider a database relation R with attributes ABCDEFG, and having the following functional dependencies: A → BCEF, E → DG, BC → A. Which of the following statements is/are correct?

    1. A is the only candidate key of R
    2. A, BC are the candidate keys of R
    3. A, BC, E are the candidate keys of R
    4. Relation R is not in Boyce-Codd Normal Form (BCNF)

    Close A, BC and E. For (D), is there an FD whose left side is not a superkey?

    A⁺ = ABCEF, then E → DG gives all 7 attributes: A is a key. BC → A, so BC⁺ is also everything; neither B nor C alone determines anything, so BC is minimal. E⁺ = EDG, not a key. So (B) ✓, (A) ✗, (C) ✗. E → DG has a left side that isn’t a superkey, so R is not in BCNF: (D) ✓. Official key: B; D.

    GATE DA 2024 sample paper · Q41 · NAT · 2 marks

    Consider a schema R(A, B, C, D, E, F) and functional dependencies A → B, C → D, and E → F. The number of superkeys of this schema is _____.

    A, C and E never appear on a right-hand side. What is ACE⁺?

    A, C, E must be in every key, and ACE⁺ = ABCDEF, so ACE is the only candidate key. A superkey is ACE plus any subset of {B, D, F}: $2^3 = 8$. (Sample paper, no official key.)

    Which functional dependency is not violated by this instance?

    ABC
    1xp
    1xq
    2yp
    3yp

    For X → Y, look for two rows with the same X but different Y.

    A → B: 1 → x (twice), 2 → y, 3 → y, consistent. B → A fails (y with 2 and 3), A → C fails (1 with p and q), C → B fails (p with x and y). Remember that the instance can only show A → B isn’t violated, not that it always holds.

    R(A, B, C, D, E, F) has the functional dependencies $\{AB \to C,\ C \to D,\ D \to A,\ BE \to F,\ F \to E\}$. How many candidate keys does R have, and how many superkeys?

    Find the attribute that is on no right-hand side. Then notice that the remaining attributes fall into two groups that never interact: what does each group need, together with that attribute, to determine everything?

    B is on no right-hand side, so B is in every key, and $B^+ = \{B\}$.

    With B, any one of A, C, D gives ABCD: $AB^+$: AB → C, C → D. $BC^+$: C → D, D → A. $BD^+$: D → A, AB → C. But none of these reaches E or F.

    With B, either E or F gives BEF: BE → F, and F → E. Neither reaches A, C or D.

    So a key is B, plus one of {A, C, D}, plus one of {E, F}: $3 \times 2 =$ 6 candidate keys (ABE, ABF, BCE, BCF, BDE, BDF).

    A superkey must contain B, a non-empty subset of {A, C, D} ($2^3 - 1 = 7$ choices) and a non-empty subset of {E, F} (3 choices): $7 \times 3 =$ 21.

    R(A, B, C, D, E, F) has the functional dependencies $\{A \to BC,\ CD \to E,\ E \to F,\ F \to A\}$. Which of the following is/are correct?

    1. $AD \to F$ follows from these dependencies.
    2. $BD \to E$ follows from these dependencies.
    3. $CE \to A$ follows from these dependencies.
    4. R has exactly three candidate keys, and each contains D.

    For each FD, compute the closure of its left side. For the keys, start from the attribute that never appears on a right-hand side and try adding one attribute at a time.

    (A) True. $AD^+$: A → BC gives ABCD; CD → E; E → F. So $AD^+$ is everything, and contains F.

    (B) False. $BD^+ = \{B, D\}$: A → BC needs A, CD → E needs C, and nothing else fires.

    (C) True. $CE^+$: E → F, F → A, A → BC, giving ABCEF, which contains A.

    (D) False. D is on no right-hand side, so it is in every key, and $D^+ = \{D\}$. Adding one attribute: AD, CD, DE and DF all close to everything (CD → E → F → A → BC; DE: E → F → A → BC; DF: F → A → BC, then CD → E). Only BD fails. That’s four keys, not three.

    Correct: A, C.

    R(A, B, C, D, E) has the functional dependencies $\{A \to B,\ B \to C,\ C \to A,\ D \to E,\ E \to C\}$.

    (i) How many non-trivial dependencies $X \to Y$, with X and Y single attributes, follow from these? (ii) How many superkeys does R have?

    For (i), compute the closure of each single attribute; every attribute in $X^+$ other than X gives one dependency. For (ii), find the candidate keys first.

    Closures: $A^+ = B^+ = C^+ = \{A, B, C\}$ (the cycle), $E^+$: E → C, then C → A, A → B, giving {A, B, C, E}; $D^+$: D → E and then everything, {A, B, C, D, E}.

    (i) Count the other attributes in each closure: 2 + 2 + 2 for A, B, C, then 4 for D and 3 for E: 13.

    (ii) D is on no right-hand side and $D^+$ is all of R, so D is the only candidate key. A superkey is D plus any subset of {A, B, C, E}: $2^4 =$ 16.

    Counting only the five listed FDs, or forgetting that E reaches A and B through C, gives too small an answer for (i).

    • Find the attributes on no right-hand side first; they belong to every key.
    • Decide “is X → Y implied?” by computing X⁺, not by hunting for axiom chains.
    • Check minimality: a key loses its key-ness if you drop any attribute.
    • Stopping the closure after one pass: keep going until nothing changes.
    • Listing a superkey such as ACD as a candidate key when AD already works.
    • Claiming an FD holds because one table instance doesn’t violate it.
    1. X → Y means equal X forces equal Y; X → Y follows from F exactly when Y ⊆ X⁺.
    2. X is a superkey when X⁺ = R; a candidate key is a minimal superkey.
    3. Attributes on no right-hand side are in every key: start the key search there.

    With F = {A → B, B → C}, what is A⁺ in R(A, B, C, D)?

    {A, B}
    Keep going: B → C fires once B is in.
    {A, B, C}
    A → B, then B → C. D is never derived.
    {A, B, C, D}
    No FD produces D.

    Which rule gives AC → BC from A → B?

    Transitivity
    Transitivity chains two FDs.
    Augmentation
    Add C to both sides.
    Reflexivity
    Reflexivity gives only trivial FDs.

    R(A, B, C) has no non-trivial FDs. Its only candidate key is

    A
    A determines nothing else.
    any single attribute
    No single attribute determines the others.
    ABC
    Only the whole set is guaranteed unique.

    Normal forms: 1NF to BCNF, and splitting tables safely

    A normal form is a test of how much redundancy a table can hold. If a dependency’s left side isn’t a key, some fact gets repeated; decomposing (splitting) the table removes the repetition, ideally without losing information or the ability to check dependencies.

    GATE asks you to name a relation’s normal form (2025 Q57), state facts about normal forms (sample Q16) and know the cost of a decomposition that doesn’t preserve dependencies (2025 Q16).

    It’s like a team sheet that repeats the coach’s name on every player’s row. Change coaches and you must fix every row (or the sheet contradicts itself); move the coach to a small Team table and the problem disappears.

    Where it shows up in GATE DA

    Highest normal form; BCNF vs 3NF facts; lossless and dependency-preserving decompositions.

    2025 Q57 · not in BCNF2025 Q16 · non-dependency-preserving needs joinsSample Q16 · BCNF and 3NF facts2026 Q61 · 3NF relations from an ER model (Part 1)
    Heat: every year, 1–2 marks
    The problem

    Suppose the league stores PlayerTeam(pid, name, team, city), where team → city. Bengaluru Backprops’ city is written once per BB player. That causes three anomalies: an update anomaly (moving BB to Mysuru means editing every BB row, and missing one leaves the data contradicting itself), an insertion anomaly (a new team can’t be recorded until it has a player, since pid is the key) and a deletion anomaly (deleting HY’s last player loses HY’s city). Splitting into Player(pid, name, team) and Team(team, city) fixes all three.

    • 1NF: every value is atomic, so there are no lists or repeating groups in a cell.
    • 2NF: 1NF, and no non-prime attribute depends on a proper part of a candidate key (no partial dependency). A relation whose keys are all single attributes is automatically in 2NF.
    • 3NF: for every non-trivial $X \to A$, either X is a superkey or A is prime. Equivalently, no non-prime attribute depends transitively on a key.
    • BCNF: for every non-trivial $X \to A$, X is a superkey. No exceptions.

    So BCNF ⊂ 3NF ⊂ 2NF ⊂ 1NF: every BCNF relation is in 3NF, but not conversely. Every relation with only two attributes is in BCNF.

    • Lossless join: $R_1 \bowtie R_2 = R$ for every legal instance (no spurious rows). Test: the common attributes $R_1 \cap R_2$ form a superkey of $R_1$ or of $R_2$.
    • Dependency preserving: every FD in F can be checked inside a single $R_i$ (using the FDs that project onto it). If not, checking the lost FD needs a join of the pieces on every update.
    • A BCNF decomposition is always possible and lossless, but may not preserve dependencies. A 3NF decomposition (synthesis) is always possible, lossless and dependency preserving.
    Try it

    Each FD is classified: fine for BCNF, a BCNF-only violation (right side prime), a partial dependency (breaks 2NF) or a transitive one (breaks 3NF). Press “Decompose into BCNF” to see the splits and whether any dependency is lost. The “3NF, not BCNF” preset is the classic case where BCNF must give up a dependency.

    R(A, B, C) with F = {AB → C, C → B}. (Think of A = player, B = team, C = coach, where each coach works for one team and each player has one coach per team.) Find the highest normal form, decompose into BCNF, and check whether the decomposition is lossless and dependency preserving.

    1. Keys: A is on no right-hand side, so it’s in every key. A⁺ = {A}. AB⁺ = ABC ✓ and AC⁺: C → B gives ABC ✓. Candidate keys AB and AC, so every attribute is prime.

      Always find the keys first: every normal-form test refers to them.

    2. AB → C has a superkey on the left. C → B doesn’t (C⁺ = CB), but B is prime, so 3NF allows it. Highest normal form: 3NF, not BCNF.

      “Right side prime” is exactly the gap between 3NF and BCNF.

    3. Split on the violating FD C → B: R₁(C, B) and R₂(A, C). Common attribute C is a key of R₁ (C → B), so the join is lossless.

      Both pieces have two attributes, so both are in BCNF.

    4. AB → C mentions A, B and C, but no piece contains all three, and it can’t be derived from the FDs inside the pieces (C → B in R₁, nothing in R₂). It is not preserved: checking it would need R₁ ⋈ R₂ after every insert.

      This is why some designers stop at 3NF.

    GATE DA 2025 · Q16 · MCQ · 1 mark

    If a relational decomposition is not dependency-preserving, which one of the following relational operators will be executed more frequently in order to maintain the dependencies?

    1. Selection
    2. Projection
    3. Join
    4. Set union

    A lost dependency spans attributes that now live in different tables. How do you bring them back together?

    To check a dependency whose attributes are split across relations, you must join them first: (C). Official key: (C).

    GATE DA 2024 sample paper · Q16 · MSQ · 1 mark

    Which of the following statements is/are TRUE?

    1. Every relation in BCNF is also in 3NF.
    2. Every relation with two attributes is in BCNF.
    3. No relation can be in both BCNF and 3NF.
    4. Every relation in 3NF is also in BCNF.

    BCNF’s condition is 3NF’s condition without the “or A is prime” escape. For two attributes, list every possible set of FDs.

    (A) ✓: BCNF is stricter. (B) ✓: with attributes A, B, the possible FDs are A → B (then A is a key), B → A (B is a key), both, or neither; in every case each left side is a superkey. (C) ✗: BCNF relations are in 3NF. (D) ✗: the R(A, B, C) example above is 3NF but not BCNF. Answer A, B. (Sample paper, no official key.)

    R(A, B, C, D) with F = {AB → C, B → D}. What is the highest normal form R satisfies?

    Find the key first. Then look at B → D: is B a proper part of the key, and is D prime?

    AB⁺ = ABCD, so AB is the only key (A and B are on no right-hand side). B → D: B is a proper part of the key and D is non-prime, a partial dependency. So R is in 1NF but not 2NF.

    R(A, B, C) with F = {A → B} is decomposed into R₁(A, B) and R₂(B, C). Is the decomposition lossless?

    The common attribute is B. Is B a superkey of R₁ or of R₂?

    B determines nothing (B⁺ = {B}), so it is a key of neither piece: lossy. For example, rows (1, x, p) and (2, x, q) project to (1, x), (2, x) and (x, p), (x, q), and the join brings back four rows, two of them spurious. Splitting into (A, B) and (A, C) instead would be lossless, since A → B.

    R(A, B, C, D, E) has the functional dependencies $\{A \to B,\ BC \to E,\ ED \to A\}$. What is the highest normal form R satisfies?

    1. 1NF, but not 2NF
    2. 3NF, but not BCNF
    3. BCNF
    4. 2NF, but not 3NF

    Find all the candidate keys first (two attributes never appear on a right-hand side), and then the prime attributes. A dependency only breaks 2NF or 3NF if its right side is non-prime.

    C and D appear on no right-hand side, and $CD^+ = \{C, D\}$. Adding one attribute: $ACD^+$: A → B, BC → E, so all of R ✓. $BCD^+$: BC → E, ED → A ✓. $CDE^+$: ED → A, A → B ✓. Keys: ACD, BCD, CDE.

    Every attribute is in some key, so every attribute is prime. A 3NF violation needs a non-prime right side, so R is in 3NF.

    A → B has a left side that isn’t a superkey ($A^+ = \{A, B\}$), so R is not in BCNF. Answer (B).

    (A) is the trap: A → B looks like a partial dependency on the key ACD, but B is prime, so it doesn’t break 2NF.

    R(A, B, C, D) has the functional dependencies $\{A \to B,\ B \to C,\ C \to D\}$. Which of the following is/are correct?

    1. Decomposing R into (A, B), (B, C), (C, D) is lossless and dependency preserving.
    2. Decomposing R into (A, B), (A, C), (C, D) is lossless but does not preserve B → C.
    3. Decomposing R into (A, B), (C, D) is lossless.
    4. In the decomposition (A, B, D), (B, C), both relations are in BCNF.

    For losslessness, join two pieces at a time and check whether the shared attributes form a key of one side. For preservation, see which FDs can be checked inside a single piece, including FDs implied on that piece.

    (A) True. (B, C) and (C, D) share C, a key of (C, D), giving (B, C, D); this shares B with (A, B), and B is a key of (B, C, D). Each FD lies inside one piece.

    (B) True. (A, B) and (A, C) share A, a key of both, giving (A, B, C); this shares C with (C, D), a key there. So it is lossless. Inside the pieces you can check A → B, A → C and C → D, but from these $B^+ = \{B\}$, so B → C is lost.

    (C) False. The pieces share no attribute, so joining them gives their Cartesian product, with spurious rows.

    (D) False. In (A, B, D), A is the key, but B → D holds there (B → C → D) and B is not a superkey of that piece.

    Correct: A, B.

    R(A, B, C, D, E, F) has the functional dependencies $\{AB \to C,\ C \to B,\ A \to D,\ D \to E,\ F \to A\}$. Of these five dependencies, how many violate BCNF, and how many violate 3NF?

    Find the candidate keys and the prime attributes. An FD violates BCNF when its left side is not a superkey; it also violates 3NF when, in addition, its right side is non-prime.

    F is on no right-hand side, and $F^+ = \{A, D, E, F\}$. Adding B: F → A, AB → C, so all of R. Adding C: C → B, then the same. Adding A, D or E gives nothing new. Keys: BF and CF; prime attributes B, C, F.

    No left side contains F with B or C, so none is a superkey: all 5 violate BCNF.

    For 3NF, look at the right sides: C (AB → C) and B (C → B) are prime, so those two are allowed. D, E and A are non-prime, so A → D, D → E and F → A violate 3NF: 3.

    F → A is even a partial dependency (F is part of the key BF), so R is not in 2NF.

    • Find all candidate keys and the prime attributes before testing any normal form.
    • Test each FD: superkey on the left (BCNF ok), else right side prime (3NF ok), else partial or transitive.
    • Check a binary decomposition with the shared-attributes-are-a-key test.
    • Using “the primary key” when the definition says “any candidate key”.
    • Assuming BCNF decompositions always preserve dependencies.
    • Calling a relation 3NF because it has no transitive dependency, without checking for partial ones.
    1. BCNF: every determinant is a superkey. 3NF: the same, or the right side is prime. 2NF: no partial dependency of a non-prime attribute.
    2. A split into R₁, R₂ is lossless when R₁ ∩ R₂ is a key of one of them; dependencies not preserved need joins to check.
    3. 3NF synthesis is always lossless and dependency preserving; BCNF is always lossless but may lose a dependency.

    In R(pid, team, city) with pid → team and team → city, the FD team → city causes R to

    violate 2NF
    The key pid is a single attribute, so nothing can depend on part of it.
    violate 3NF
    A non-key determines a non-prime attribute: a transitive dependency.
    be in BCNF
    team isn’t a superkey.

    Which decomposition property can BCNF fail to guarantee?

    Lossless join
    BCNF decomposition always splits on a key of one piece, so it’s lossless.
    Dependency preservation
    Some FDs (like AB → C with C → B) can’t survive the split.
    Atomic values
    That’s 1NF, which every decomposition keeps.

    A relation stores a player’s phone numbers as “98…, 97…” in one cell. It violates

    1NF
    A cell must hold a single atomic value.
    only BCNF
    It fails the most basic test, 1NF.
    no normal form
    Lists in a cell break atomicity.

    R(A, B, C, D), F = {A → B, B → C, C → A}. How many candidate keys?

    1
    A, B and C determine each other.
    3
    D is in every key; AD, BD and CD are all keys.
    4
    D alone determines nothing.

    Every relation whose candidate keys are all single attributes is in at least

    1NF only
    Partial dependencies need a key with two or more attributes.
    2NF
    A single-attribute key has no proper non-empty part, so no partial dependency.
    BCNF
    Transitive dependencies are still possible.

    An M : N relationship mapped to R(pid, sid) with no other attributes is in

    1NF only
    It has two attributes.
    3NF but not BCNF
    Two-attribute relations are always in BCNF.
    BCNF
    Every two-attribute relation is in BCNF.

    A lossy decomposition, when joined back, produces

    fewer rows than the original
    Projection then join can never lose original rows.
    extra (spurious) rows
    The original rows all return, plus combinations that never existed.
    exactly the original
    That’s the definition of lossless.

    Three syllabus topics that sit around the database itself. File organisation and indexing (B+ trees and hashing) decide how fast a query runs. Data transformation (normalisation, discretisation, sampling, compression) prepares data for analysis. Data warehousing (star schemas, concept hierarchies, data cubes and OLAP operations) organises it for reporting. GATE 2026 alone asked five questions from this part.

    You need: Parts 1–3; binary search trees from Python & DSA; z-scores from Statistics.

    File organisation and indexing: B+ trees and hash indexes

    Tables live on disk in fixed-size blocks, and reading a block is slow. An index is a small structure that tells you which block holds the rows you want; a B+ tree index stays balanced and shallow, so any key is a few block reads away.

    GATE asks you to compute a B+ tree’s fan-out from block and pointer sizes (2026 Q32), its minimum height (sample Q40), the effect of an insertion (2026 Q41), and which index suits which query (2024 Q55).

    It’s like a library: the catalogue (index) sends you to the right shelf (block). A B+ tree is a catalogue of catalogues: three lookups find any book among millions.

    Where it shows up in GATE DA

    Node capacity, height, insertion with splits, choosing an index type.

    2026 Q41 · root after inserting into a B+ tree2026 Q32 · pointers in a non-leaf nodeSample Q40 · minimum height for 100,000 records2024 Q55 · hash vs B+ tree index
    Heat: every year, 1–2 marks
    • Block: the unit of disk transfer (e.g. 4096 bytes). Blocking factor = ⌊block size / record size⌋ records per block. Cost is counted in block accesses.
    • File organisations: heap (unordered; insert is cheap, search scans every block), sorted/sequential (ordered on a field; binary search on blocks), hashed (a hash of the key picks the bucket).
    • Primary index: on the ordering key field of a sorted file, one entry per block (sparse). Clustering index: on an ordering non-key field. Secondary index: on any other field, one entry per record (dense). A file has at most one primary or clustering index, but many secondary ones.
    • B+ tree: a balanced search tree whose leaves hold every key with a pointer to its record, and are linked left to right; internal nodes hold only separator keys and child pointers. All leaves are at the same depth. (In a B tree, internal nodes also carry record pointers, and each key appears once.)
    • Hash index: excellent for equality (= 'Comedy'), useless for ranges (> 3.4), because hashing scatters neighbouring values. A B+ tree handles both, since its leaves are sorted.
    • Internal node with p child (node) pointers and p − 1 keys: $p \cdot P_{node} + (p-1)\cdot K \le B$. The largest such p is the order (fan-out).
    • Leaf with n keys, n record pointers and one next-leaf pointer: $n(K + P_{rec}) + P_{node} \le B$.
    • Insert: put the key in its leaf; if the leaf overflows, split it in half and copy a separator up; if a parent overflows, split it and move its middle key up. A root split adds a level: the tree grows at the top.
    • Minimum height (all nodes full): leaves needed = ⌈records / leaf capacity⌉; each level above divides by the fan-out (rounding up) until one node remains.
    Try it

    Insert keys into a B+ tree and read the log of splits. “Load 2026 Q41” builds the tree from that question; insert 3 and see the leaf split, the parent overflow and the new root. Then clear it and press “Insert 1–10 in order” with different capacities to see how the height grows.

    GATE DA 2026 · Q41 · MCQ · 2 marks

    Consider a B+ Tree where the maximum number of key values in each leaf node is 2 and the maximum number of pointers in each non-leaf node is 3. Let the content of the B+ Tree be as shown in the figure.

    Which of the following options denotes the key value(s) stored in the root node after inserting a key value 3 in the given B+ Tree?

    1. 5
    2. 8
    3. 3 and 5
    4. 3, 5 and 8

    (Figure redrawn from the paper.)

    1. 3 belongs in the first leaf [1, 5] (the figure keeps keys ≤ 5 to the left of separator 5). It becomes [1, 3, 5]: three keys, but the maximum is 2, so the leaf splits into [1, 3] and [5], and the separator 3 is copied up.

      Leaf splits copy a key up; the key also stays in a leaf, since leaves must hold every key.

    2. The root would become [3, 5, 8] with four child pointers, but non-leaf nodes allow at most 3. It splits into [3] and [8] (two pointers each) and the middle key 5 moves up into a new root.

      Internal splits move the middle key; it doesn’t stay below.

    3. The new root holds only 5: answer (A). The tree is now one level taller.

      (D) is the overflowing node before the split; (C) forgets that 8 goes to the right half. Official key: (A).

    GATE DA 2026 · Q32 · NAT · 1 mark

    In a relational database, a B+ Tree Index is to be constructed for a relation on a key field. In a B+ Tree, a Node Pointer points to a sub-tree and a Data Record Pointer points to a block of database records. Let, Node size = 4096 bytes, Node Pointer size = 10 bytes, Search Key Field size = 11 bytes and Data Record Pointer size = 12 bytes. The maximum number of Node Pointers that can be present in a non-leaf node of the B+ Tree is ________ . (Answer in integer)

    A non-leaf node with p node pointers holds p − 1 keys and no record pointers.

    $10p + 11(p - 1) \le 4096$, so $21p \le 4107$ and $p \le 195.57$: p = 195. (Check: 1950 + 2134 = 4084 ≤ 4096, while 196 needs 4105.) The record-pointer size is a distractor; it matters only for leaves. Official key: 195.

    GATE DA 2024 sample paper · Q40 · NAT · 2 marks

    A file with 100,000 records is indexed with B+ tree. If the size of a memory block is 2K bytes, the size of a key is 4 bytes, the size of a pointer is 4 bytes, the minimum possible height of the B+ tree index is ______. Height is always greater than or equal to 1. Hints: No records are stored in the nodes, only keys are stored. The sizes of the pointers are same, irrespective of whether they point to a node or a record.

    Leaf: n keys + n record pointers + 1 next pointer. Internal: p pointers + (p − 1) keys. Then count levels from 100,000 records upward.

    Leaf: $8n + 4 \le 2048$ gives n = 255. Internal: $4p + 4(p-1) \le 2048$ gives p = 256. Leaves: ⌈100000/255⌉ = 393. Next level: ⌈393/256⌉ = 2 nodes, then 1 root. Levels: leaves, 2 internal nodes, root, so height 3. (Sample paper, no official key; height counted in levels, as the question’s “≥ 1” implies.)

    GATE DA 2024 · Q55 · MSQ · 2 marks

    An OTT company is maintaining a large disk-based relational database of different movies with the following schema: Movie(ID, CustomerRating), Genre(ID, Name), Movie_Genre(MovieID, GenreID). Consider the following SQL query on the relation database above:

    SELECT *
    FROM Movie, Genre, Movie_Genre
    WHERE
        Movie.CustomerRating > 3.4 AND
        Genre.Name = “Comedy” AND
        Movie_Genre.MovieID = Movie.ID AND
        Movie_Genre.GenreID = Genre.ID;

    This SQL query can be sped up using which of the following indexing options?

    1. B + tree on all the attributes.
    2. Hash index on Genre.Name and B + tree on the remaining attributes.
    3. Hash index on Movie.CustomerRating and B + tree on the remaining attributes.
    4. Hash index on all the attributes.

    Which condition is a range? A hash index can’t serve a range.

    CustomerRating > 3.4 is a range condition, so it needs a B+ tree; the other conditions are equalities, which a B+ tree or a hash index both serve. (A) ✓ and (B) ✓; (C) and (D) put a hash index on the range attribute. Official key: A; B.

    Block size 1024 bytes, key 9 bytes, record pointer 7 bytes, node (block) pointer 6 bytes. At most how many keys fit in a B+ tree leaf (each key with its record pointer, plus one pointer to the next leaf)?

    $n(9 + 7) + 6 \le 1024$.

    $16n \le 1018$, so n = 63 (63 × 16 + 6 = 1014).

    A file of 30,000 records, each 100 bytes, is sorted on its key and stored in 1024-byte blocks (records don’t span blocks). A primary (sparse) index has one entry per data block, each entry a 9-byte key and a 7-byte block pointer.

    (i) To find a record, you binary-search the index blocks and then read one data block. A binary search over b blocks reads $\lceil \log_2 b \rceil$ blocks. How many block accesses in all?

    (ii) The index is made multilevel: an index on the index, and so on, until one block remains. How many block accesses now, including the data block?

    Find the blocking factor and the number of data blocks; that is the number of index entries. Then find how many entries fit in a block, and how many blocks the index needs.

    Blocking factor ⌊1024/100⌋ = 10, so the file has 30000/10 = 3000 blocks and the index has 3000 entries.

    Entries per index block: ⌊1024/16⌋ = 64, so the index needs ⌈3000/64⌉ = 47 blocks.

    (i) ⌈log₂ 47⌉ = 6 index blocks, plus 1 data block: 7.

    (ii) The second level indexes 47 blocks: ⌈47/64⌉ = 1 block, so it is the top. Read one block per level (2) and then the data block: 3.

    For comparison, a binary search on the data file itself reads ⌈log₂ 3000⌉ = 12 blocks.

    A B+ tree is built on a key field with block size 512 bytes, key 8 bytes, node (block) pointer 6 bytes and record pointer 8 bytes. A leaf holds keys with their record pointers plus one pointer to the next leaf.

    (i) What is the maximum number of node pointers in an internal node? (ii) What is the maximum number of keys a B+ tree with exactly 3 levels (root, one internal level, leaves) can index?

    Write the internal-node and leaf inequalities separately; internal nodes have no record pointers. With every node full, the root has p children, each of those has p children, and each leaf holds its maximum.

    (i) $6p + 8(p - 1) \le 512$ gives $14p \le 520$, so $p = 37$ (37 needs 510 bytes; 38 would need 524).

    Leaf: $16n + 6 \le 512$ gives $n = 31$ (502 bytes).

    (ii) Root: 37 children; second level: 37 × 37 = 1369 leaves; each holds 31 keys: 1369 × 31 = 42439.

    Using the 8-byte record pointer in the internal node gives 32 pointers, a common slip.

    In a B+ tree a leaf holds at most 3 keys and an internal node at most 3 pointers (so 2 keys). When a leaf overflows to 4 keys it splits 2 + 2, and the first key of the new right leaf is copied up. When an internal node overflows to 3 keys, the middle key moves up.

    Starting from an empty tree, the keys 10, 20, 30, 40, 50, 60, 70, 80 are inserted in that order. After the last insertion, what key does the root hold, and how many nodes does the tree have?

    Draw the tree after each split; there are only three. Watch the difference between copying a key up from a leaf and moving a key up from an internal node.

    10, 20, 30 fill one leaf. 40 overflows it: [10, 20] and [30, 40], and 30 is copied into a new root [30].

    50 joins [30, 40, 50]. 60 overflows it: [30, 40] and [50, 60], and 50 is copied up: root [30, 50]. 70 joins [50, 60, 70].

    80 overflows that leaf: [50, 60] and [70, 80], and 70 is copied up. The root would become [30, 50, 70] with 4 pointers, so it splits into [30] and [70], and 50 moves up into a new root.

    Final tree: root [50]; internal nodes [30] and [70]; leaves [10, 20], [30, 40], [50, 60], [70, 80]. That’s 1 + 2 + 4 = 7 nodes in 3 levels.

    • Write the capacity inequality for the node type asked (leaf or internal) before plugging in numbers.
    • Round capacities down and level counts up.
    • Pick a B+ tree for ranges and a hash index only for equality.
    • Using record pointers in an internal-node calculation.
    • Moving (instead of copying) the separator when a leaf splits.
    • Forgetting the leaf’s next-leaf pointer.
    1. Internal node: p·P + (p − 1)·K ≤ B; leaf: n·(K + P_rec) + P ≤ B.
    2. Leaf splits copy a separator up; internal splits move the middle key up; the tree grows only at the root, so all leaves stay level.
    3. Hash indexes serve equality only; B+ trees serve equality and ranges, thanks to sorted, linked leaves.

    A query asks for runs BETWEEN 200 AND 300. The best index on runs is

    a hash index
    Hashing scatters neighbouring values; ranges need order.
    a B+ tree
    Find 200, then walk the linked leaves to 300.
    no index helps
    A sorted index helps a lot.

    Records are 100 bytes and blocks 4096 bytes (records don’t span blocks). The blocking factor is

    41
    Round down: a partial record doesn’t fit.
    40
    ⌊4096/100⌋ = 40.
    4096
    That’s bytes, not records.

    A secondary index on a non-ordering field is

    sparse
    The file isn’t ordered on this field, so one entry per block can’t work.
    dense
    One entry per record, since matching records can be anywhere.
    impossible
    A file can have many secondary indexes.

    Data transformation: normalise, discretise, sample, compress

    Before data is analysed it is usually transformed: rescaled to a common range (normalisation), grouped into bins (discretisation), reduced to a representative subset (sampling) or stored in less space (compression).

    GATE 2024 Q27 asked for a z-score normalised value (worked in Statistics, Ch. 1.1). The other techniques are short computations of the same kind.

    It’s like preparing a season review: convert runs and strike rates to comparable scales, label players as low, medium or high scorers, interview a fair sample of fans, and zip the archive.

    Where it shows up in GATE DA

    Short numerical questions on transformed values; names of techniques.

    2024 Q27 · z-score normalisation (Statistics Ch. 1.1)2026 Q23 · sampling (MCMC) in an ML matching question
    Heat: 2024, 1 mark; low but cheap marks
    • Nominal: names or categories with no order (team). Binary: two values (is captain). Ordinal: ordered categories (low < medium < high).
    • Numeric: interval (differences meaningful, no true zero, e.g. temperature in °C) or ratio (true zero, so ratios are meaningful, e.g. runs).
    • Min–max to $[a, b]$: $x' = a + \dfrac{x - \min}{\max - \min}(b - a)$. With $[0, 1]$: $x' = \dfrac{x - \min}{\max - \min}$.
    • z-score: $x' = \dfrac{x - \bar x}{s}$. Mean 0 and SD 1 afterwards; good when min and max are distorted by outliers.
    • Decimal scaling: $x' = x / 10^j$, with j the smallest integer that makes every $|x'| \lt 1$.
    • Equal-width binning: k intervals of width (max − min)/k. Simple, but outliers leave bins nearly empty. Equal-frequency (equal-depth): each bin gets n/k values.
    • Smoothing replaces values by their bin’s mean (or median), or by the nearer bin boundary (the bin’s min or max).
    • Discretisation by concept hierarchy: replace low-level values with higher-level ones (city → state → country). Section 5.3 builds data cubes on such hierarchies.
    • Sampling: simple random sampling without replacement (SRSWOR) or with replacement (SRSWR); stratified (sample within each group, usually in proportion to its size); cluster (pick whole groups at random).
    • Compression / data reduction: lossless (the original can be rebuilt exactly) or lossy (an approximation). Dimensionality reduction (PCA, wavelet transforms) and numerosity reduction (histograms, clustering, sampling) shrink data while keeping its main structure.
    Try it

    Twelve players’ runs, 4 to 90. Compare equal-width and equal-frequency bins and see how the outliers 62 and 90 distort equal-width bins. Turn on smoothing to see each value replaced by its bin mean or nearest boundary. Then switch to “Normalise” and compare min–max, z-score and decimal scaling on the same data.

    The sorted runs are 4, 8, 15, 21, 21, 24, 25, 28, 34, 45, 62, 90. Partition them into 3 equal-frequency bins, then smooth by bin means and by bin boundaries.

    1. 12 values in 3 bins: 4 per bin. Bin 1 = {4, 8, 15, 21}, bin 2 = {21, 24, 25, 28}, bin 3 = {34, 45, 62, 90}.

      Equal-frequency bins can split equal values (the two 21s) across bins; that’s acceptable.

    2. Means: 48/4 = 12, 98/4 = 24.5, 231/4 = 57.75. Smoothing by means replaces every value in a bin with that mean.

      This hides the noise within a bin but keeps the bins’ overall levels.

    3. Boundaries: each value moves to the nearer of its bin’s min and max. Bin 1: 4, 4, 21, 21 (8 is 4 from 4 and 13 from 21). Bin 2: 21, 21, 28, 28. Bin 3: 34, 34, 34, 90 (62 is 28 from both ends; ties go to the lower boundary here).

      Ties need a convention; questions usually avoid them.

    Using min–max normalisation to [0, 1] on the runs above (min 4, max 90), what does 34 become?

    $(x - \min)/(\max - \min)$.

    $(34 - 4)/(90 - 4) = 30/86 \approx 0.349$.

    An attribute ranges from −986 to 917. Using decimal scaling, what does −986 become?

    The largest absolute value is 986; find the smallest j with 986/10^j < 1.

    j = 3, so −986 → −0.986 (and 917 → 0.917).

    Split the same 12 runs into 4 equal-width bins. How many values fall in the first bin?

    Width = (90 − 4)/4 = 21.5, so the first bin is [4, 25.5).

    4, 8, 15, 21, 21, 24 and 25 are below 25.5: 7 values, more than half the data in one bin, because 90 stretches the range.

    The five DPL squads have 20, 30, 10, 25 and 15 players. A proportional stratified sample of 20 players is drawn. How many come from the 30-player squad?

    Each squad contributes in proportion to its size out of 100.

    20 × 30/100 = 6.

    Five values of an attribute are 12, 15, 18, 25 and 30. Normalise the value 25 in two ways: (i) min–max normalisation to the range [−1, 1]; (ii) z-score normalisation, using the population standard deviation (divide by n). (Round off to three decimal places.)

    For (i), use $x' = a + \dfrac{x - \min}{\max - \min}(b - a)$ with $a = -1$ and $b = 1$. For (ii), find the mean and the squared deviations first.

    (i) $x' = -1 + \dfrac{25 - 12}{30 - 12}\times 2 = -1 + \dfrac{26}{18} = \dfrac49 \approx$ 0.444.

    (ii) The mean is 100/5 = 20. Deviations −8, −5, −2, 5, 10; squares 64, 25, 4, 25, 100, summing to 218. Variance 218/5 = 43.6, SD $\sqrt{43.6} \approx 6.603$. So $z = 5/6.603 \approx$ 0.757.

    Forgetting the target range in (i) gives 13/18 ≈ 0.722; using the sample SD (divide by 4) in (ii) gives 0.677.

    The sorted data are 5, 7, 9, 14, 20, 22, 26, 33, 41. The value 22 is smoothed in two ways: (i) 3 equal-width bins, smoothing by bin means; (ii) 3 equal-frequency bins, smoothing by bin boundaries. What does 22 become in each case?

    1. 22.67 and 22
    2. 18.67 and 20
    3. 22.67 and 20
    4. 18.67 and 22

    Equal-width bins have width (max − min)/3; equal-frequency bins hold 3 values each. 22 lands in a different bin each time. In boundary smoothing, a value moves to the nearer of its bin’s min and max.

    (i) Width (41 − 5)/3 = 12: bins [5, 17), [17, 29), [29, 41]. 22 is in {20, 22, 26}, whose mean is 68/3 ≈ 22.67.

    (ii) Bins {5, 7, 9}, {14, 20, 22}, {26, 33, 41}. 22 is in the middle bin, and it is that bin’s maximum, so it stays 22.

    Answer (A). The other options mix the two binnings: (B) is equal-frequency means with equal-width boundaries; (C) uses equal-width bins for both; (D) uses equal-frequency bins for both.

    Which of the following is/are correct?

    1. A proportional stratified sample of 40 from strata of sizes 120, 80 and 200 takes 8 from the stratum of 80.
    2. There are 20 different simple random samples of size 2, drawn without replacement, from 5 players.
    3. If an attribute ranges from −250 to 1000, decimal scaling maps 1000 to 1.
    4. Min–max normalisation to [0, 10] gives exactly 10 times the min–max normalised value in [0, 1].

    Check each one with a small calculation. For (B), does order matter in a sample? For (C), recall the exact condition that fixes j.

    (A) True. The strata total 400, so the stratum of 80 gets 40 × 80/400 = 8.

    (B) False. A sample is a set, so order doesn’t matter: $\binom52 = 10$. 20 counts ordered draws.

    (C) False. j is the smallest integer that makes every $|x'| \lt 1$. With j = 3, 1000 becomes 1, which is not below 1, so j = 4 and 1000 maps to 0.1.

    (D) True. With a = 0 and b = 10, $x' = 0 + \dfrac{x - \min}{\max - \min}\times 10$, which is 10 times the [0, 1] value. (This works because a = 0; for [5, 10] it would not.)

    Correct: A, D.

    • Use z-scores when outliers would distort min–max.
    • Sort the data before binning by frequency.
    • Use stratified sampling when groups differ a lot and each must be represented.
    • Mixing up min–max and z-score formulas.
    • Forgetting the target range [a, b] in min–max scaling.
    • Calling PCA lossless: dropping components loses information.
    1. Min–max maps to a fixed range; z-score centres on the mean in SD units; decimal scaling divides by a power of 10.
    2. Equal-width bins have equal ranges, equal-frequency bins equal counts; smoothing replaces values by bin means or boundaries.
    3. Sampling (random, stratified, cluster) and compression (lossless or lossy, e.g. PCA) reduce data while keeping its structure.

    After z-score normalisation, the data has

    range [0, 1]
    That’s min–max.
    mean 0 and standard deviation 1
    Subtracting the mean and dividing by the SD does exactly this.
    all values below 1 in size
    That’s decimal scaling.

    “Low / medium / high scorer” is an attribute of type

    nominal
    These categories have a natural order.
    ordinal
    Ordered categories, without meaningful differences.
    ratio
    There are no numbers to take ratios of.

    Choosing 3 of the 5 teams at random and surveying all their fans is

    stratified sampling
    Stratified samples within every group.
    cluster sampling
    Whole groups are chosen at random.
    simple random sampling
    That would pick individual fans directly.

    Data warehouses: star schemas, cubes and OLAP operations

    A data warehouse stores history for analysis: a central fact table of numbers (tickets sold) linked to dimension tables (team, time, seat). Summing the facts over any choice of dimensions gives a cuboid, and all the cuboids together form a data cube.

    GATE asks you to count cuboids from concept hierarchies (2026 Q43), count the rows of a GROUP BY CUBE query (2025 Q46) and name an OLAP operation (2026 Q18).

    It’s like a league ticketing report: totals by team and month, then by zone and season, then just the grand total. Each view is a different cuboid of the same cube.

    Where it shows up in GATE DA

    Counting cuboids and CUBE rows; naming OLAP operations.

    2026 Q43 · cuboids from concept hierarchies2025 Q46 · rows of GROUP BY CUBE2026 Q18 · Country → State is a drill-down
    Heat: 2025–26, 1–2 marks each year
    • OLTP systems run day-to-day transactions on current, normalised data; an OLAP warehouse holds integrated, historical, read-mostly data for analysis.
    • Fact table: the measures (tickets, revenue) plus a foreign key to each dimension. Dimension tables: descriptive attributes (team name, zone; month, season).
    • Star schema: one fact table, each dimension a single denormalised table. Snowflake schema: dimensions normalised into several tables (team → zone table). Fact constellation (galaxy): several fact tables sharing dimensions.
    • Concept hierarchy: levels of a dimension from fine to coarse, e.g. day < month < year, city < state < country, with a top level ALL.
    • Measures by how they combine: distributive (sum, count, min, max: combine partial results directly), algebraic (average, standard deviation: computed from a fixed number of distributive ones, e.g. sum and count), holistic (median, mode, rank: need all the data).
    • n dimensions without hierarchies: $2^n$ cuboids (each dimension is in or out), from the base cuboid down to the apex (ALL, …, ALL).
    • With hierarchies, where dimension i has $L_i$ levels (not counting ALL): $\prod_i (L_i + 1)$ cuboids.
    • GROUP BY CUBE(D1, …, Dn) computes all $2^n$ groupings. If every combination is present, its row count is $\prod_i (|D_i| + 1)$.
    • GROUP BY ROLLUP(D1, …, Dn) computes only the n + 1 prefixes (D1…Dn), (D1…Dn−1), …, (). For two dimensions: $|D_1||D_2| + |D_1| + 1$ rows.
    • Roll-up: climb a hierarchy (month → season) or drop a dimension; fewer, coarser rows.
    • Drill-down: the reverse (country → state, season → month); more, finer rows.
    • Slice: fix one dimension to a single value (season = 2026), giving a sub-cube with one dimension fewer.
    • Dice: select values on two or more dimensions, giving a smaller sub-cube.
    • Pivot (rotate): swap the axes of the view; the data doesn’t change.
    Try it

    A DPL ticket-sales cube with three dimensions: Team (team → zone → ALL), Time (month → season → ALL) and Seat (seat → ALL). Change a level to roll up or drill down, and use the “=” menus to slice and dice. The readout names each operation and the cuboid you’re looking at; count how the rows change.

    GATE DA 2026 · Q43 · MCQ · 2 marks

    Consider the concept hierarchies as shown in the figure.

    Which of the following options denotes the total number of possible data cuboids from these concept hierarchies?

    1. $4^3$
    2. $2^3$
    3. $2!$
    4. $4!$

    (Figure redrawn from the paper.)

    1. Each dimension has 3 levels, plus the implicit top level ALL (the dimension is summed out): 4 choices per dimension.

      ALL is what makes “this dimension isn’t in the cuboid” possible.

    2. The choices are independent across the 3 dimensions: $4 \times 4 \times 4 = 4^3 = 64$ cuboids. Answer (A).

      $2^3$ would be right only without hierarchies (each dimension in or out). Official key: (A).

    GATE DA 2025 · Q46 · MCQ · 2 marks

    Consider a fact table in an OLAP application: Facts(D1, D2, val), where D1 and D2 are its dimension attributes and val is a dependent attribute. Suppose attribute D1 takes 3 values and D2 takes 2 values, and all combinations of these values are present in the table Facts. How many tuples are there in the result of the following query?

    SELECT D1, D2, sum(val)
    FROM Facts
    GROUP BY CUBE (D1, D2);
    1. 1
    2. 6
    3. 9
    4. 12

    CUBE computes the groupings (D1, D2), (D1), (D2) and (). Count the rows of each.

    (D1, D2): 6 rows; (D1): 3; (D2): 2; (): 1. Total 12 = (3 + 1)(2 + 1): (D). Official key: (D).

    GATE DA 2026 · Q18 · MCQ · 1 mark

    Consider that the visualization of a 3-dimensional data cube is showing Sales Quantity for each combination of the attributes Product Type, Month and Country. From this, if we want to further visualize the Sales Quantity for each combination of Product Type, Month and State, which of the following OLAP operations should be performed?

    1. Slicing
    2. Dicing
    3. Roll-up
    4. Drill-down

    Is State finer or coarser than Country in the location hierarchy?

    Country → State moves to a finer level of the hierarchy: drill-down (D). Official key: (D).

    Same Facts table (D1 has 3 values, D2 has 2, all 6 combinations present). How many rows does GROUP BY ROLLUP (D1, D2) return?

    ROLLUP computes only (D1, D2), (D1) and ().

    6 + 3 + 1 = 10. It skips the (D2) grouping that CUBE includes.

    The median ticket price per match, as a warehouse measure, is

    Can you combine the medians of two halves of the data into the overall median?

    Holistic: medians of parts don’t determine the median of the whole, so all the values are needed. (Sum is distributive; average is algebraic, since it’s sum/count.)

    A sales warehouse has a star schema with four dimensions: Time (day < month < quarter < year), Location (city < state), Product (item < category) and Customer (no hierarchy). (i) How many cuboids does the data cube have? (ii) In how many of them is at least one dimension at its finest level (day, city, item or customer)?

    Each dimension contributes its levels plus ALL. For (ii), it is easier to count the cuboids in which no dimension is at its finest level, and subtract.

    (i) Choices per dimension: Time 4 + 1, Location 2 + 1, Product 2 + 1, Customer 1 + 1. Cuboids: $5 \times 3 \times 3 \times 2 =$ 90.

    (ii) No dimension at its finest level: Time has 4 choices (month, quarter, year, ALL), Location 2 (state, ALL), Product 2 (category, ALL), Customer 1 (ALL). That’s $4 \times 2 \times 2 \times 1 = 16$ cuboids.

    So $90 - 16 =$ 74 cuboids have at least one dimension at its finest level.

    Using $2^4 = 16$ for (i) ignores the hierarchies.

    A fact table records ticket sales. Not every (team, season) combination occurs.

    Facts
    teamseasontickets
    KK202510
    KK202612
    HH20258
    BB20265
    BB20267
    Q1: SELECT team, season, SUM(tickets) FROM Facts
        GROUP BY CUBE (team, season);
    Q2: SELECT team, season, SUM(tickets) FROM Facts
        GROUP BY ROLLUP (team, season);

    The numbers of rows returned by Q1 and Q2 are

    1. 12 and 10
    2. 10 and 8
    3. 11 and 9
    4. 12 and 8

    List the groupings each query computes, and count the groups that actually occur in the data for each one. The formula $(|D_1| + 1)(|D_2| + 1)$ needs every combination to be present.

    Groups by (team, season): (KK, 2025), (KK, 2026), (HH, 2025), (BB, 2026), so 4; the two BB 2026 rows form one group. By team: 3. By season: 2. Grand total: 1.

    CUBE computes all four groupings: 4 + 3 + 2 + 1 = 10. ROLLUP computes (team, season), (team) and (): 4 + 3 + 1 = 8. Answer (B).

    (A) uses $(3 + 1)(2 + 1) = 12$, which assumes all 6 combinations are present. (C) counts the 5 fact rows as 5 groups. (D) mixes the formula for CUBE with the right count for ROLLUP.

    A measure is stored in two partitions of a warehouse: partition 1 holds the values 2, 4, 6 and partition 2 holds 10, 20. Which of the following is/are correct?

    1. The overall average, 8.4, can be computed from each partition’s sum and count alone.
    2. The overall average equals the average of the two partition averages.
    3. The overall median equals the average of the two partition medians.
    4. The overall population variance, 40.64, can be computed from each partition’s count, sum and sum of squares, so variance is an algebraic measure.

    Compute the overall values directly from all five numbers, then check whether each partition summary is enough to reproduce them.

    (A) True. Sums 12 and 30, counts 3 and 2: (12 + 30)/(3 + 2) = 42/5 = 8.4. Average is algebraic: a fixed number of distributive values (sum, count) suffice.

    (B) False. The partition averages are 4 and 15, and their average is 9.5. Averaging averages ignores that the partitions have different sizes.

    (C) False. The overall median of 2, 4, 6, 10, 20 is 6, while the partition medians 4 and 15 average to 9.5. Median is holistic.

    (D) True. Sums of squares are 56 and 500, so the mean square is 556/5 = 111.2, and the variance is 111.2 − 8.4² = 111.2 − 70.56 = 40.64. Three distributive values per partition are enough.

    Correct: A, D.

    • Count levels per dimension, add 1 for ALL, and multiply.
    • List CUBE’s groupings explicitly when counting rows.
    • Decide whether the new view is finer (drill-down) or coarser (roll-up) before naming the operation.
    • Using $2^n$ when the dimensions have hierarchies.
    • Confusing CUBE (all $2^n$ groupings) with ROLLUP (n + 1 prefixes).
    • Calling a single-value filter a dice (it’s a slice).
    1. Fact table of measures plus dimension tables: a star schema (snowflake if the dimensions are normalised).
    2. Cuboids = ∏ (levels + 1); CUBE over n attributes has 2^n groupings and ∏ (|Dᵢ| + 1) rows; ROLLUP has n + 1 groupings.
    3. Roll-up goes coarser, drill-down finer; slice fixes one dimension, dice several; measures are distributive, algebraic or holistic.

    Four dimensions, no hierarchies. How many cuboids?

    4
    Each dimension can be in or out of a cuboid.
    8
    That’s three dimensions.
    16
    $2^4$.

    In a snowflake schema, the dimension tables are

    merged into the fact table
    Dimensions stay separate from the facts.
    normalised into several related tables
    E.g. Team links to a separate Zone table.
    removed
    Without dimensions, there’s nothing to analyse by.

    Going from sales by (month, team) to sales by (season, team) is

    a drill-down
    Season is coarser than month.
    a roll-up
    Climbing the time hierarchy aggregates months into seasons.
    a slice
    No value is fixed.

    Inserting keys into a B+ tree can increase its height only by

    adding a leaf below the deepest level
    All leaves stay at the same depth.
    splitting the root
    B+ trees grow at the top, which keeps them balanced.
    rotating a subtree
    Rotations belong to AVL and red–black trees.

    Equal-width binning of data with one huge outlier tends to

    give every bin the same count
    That’s equal-frequency binning.
    crowd most values into one bin
    The outlier stretches the range, so the bins are wide.
    remove the outlier
    Binning groups values; it doesn’t delete them.

    GROUP BY CUBE(team, season) with 5 teams and 2 seasons (all combinations present) returns

    10 rows
    That’s only the (team, season) grouping.
    16 rows
    That’s ROLLUP: 10 + 5 + 1.
    18 rows
    (5 + 1)(2 + 1) = 10 + 5 + 2 + 1.

    Star schemas deliberately keep each dimension in one denormalised table because

    warehouses never have functional dependencies
    They do (team → zone, for example).
    fewer joins make analytical queries faster, and the data is rarely updated
    Update anomalies matter little in a read-mostly warehouse.
    BCNF is impossible for dimension tables
    They could be normalised; that’s the snowflake schema.
    Every module complete

    Every question, answered right.

    You worked through every quiz and every practice problem in GATE Data Science & AI. That took real effort, and the understanding is yours to keep. Add your name to make a certificate.