Skip to content
dronacharya.ai

DBMS and SQL interview questionswith answers and explanations

23 original DBMS and SQL questions of the kind asked in technical MCQ rounds and interviews, each with the answer and a short explanation. To answer them yourself first, open the CS fundamentals practice.

questions
23
easy
12
medium
8
hard
3
  1. Question 1

    Easy

    Which normal form removes transitive dependencies of non-key attributes on the primary key?

    1. A1NF
    2. B2NF
    3. C3NFAnswer
    4. D4NF

    Explanation

    3NF requires that no non-key attribute depends on the key through another non-key attribute.

  2. Question 2

    Easy

    Table Emp(id, dept, salary). Which query returns the number of employees in each department?

    1. ASELECT dept, COUNT(*) FROM Emp GROUP BY dept;Answer
    2. BSELECT dept, COUNT(*) FROM Emp;
    3. CSELECT COUNT(dept) FROM Emp GROUP BY id;
    4. DSELECT dept FROM Emp HAVING COUNT(*) > 0;

    Explanation

    GROUP BY dept makes one group per department, and COUNT(*) counts rows in each group.

  3. Question 3

    Easy

    Which ACID property guarantees that a committed transaction's changes survive a crash?

    1. AAtomicity
    2. BConsistency
    3. CIsolation
    4. DDurabilityAnswer

    Explanation

    Durability means committed data is persisted, typically through a write-ahead log.

  4. Question 4

    Easy

    Which key uniquely identifies each row of a table and can never be NULL?

    1. AForeign key
    2. BPrimary keyAnswer
    3. CA column with a DEFAULT value
    4. DAny indexed column

    Explanation

    A primary key must be unique and NOT NULL. A foreign key refers to a key elsewhere and may repeat or be NULL, and an ordinary index does not force uniqueness.

  5. Question 5

    Easy

    Which SQL statement removes a table completely, both its structure and its data?

    1. ADELETE FROM
    2. BTRUNCATE TABLE
    3. CALTER TABLE
    4. DDROP TABLEAnswer

    Explanation

    DROP TABLE removes the table definition along with its rows. DELETE and TRUNCATE remove rows but keep the empty table, and ALTER TABLE changes its structure.

  6. Question 6

    Easy

    What is a foreign key?

    1. AA column whose values must match a key in another table (or the same table)Answer
    2. BThe primary key of the same table under another name
    3. CA key stored outside the database
    4. DA column whose values must all be different

    Explanation

    A foreign key enforces referential integrity: each value must exist in the referenced key column, such as Orders.customer_id pointing to Customers.id.

  7. Question 7

    Easy

    Which join returns every row of the left table, with NULLs in the right table's columns where there is no match?

    1. AINNER JOIN
    2. BLEFT JOINAnswer
    3. CRIGHT JOIN
    4. DCROSS JOIN

    Explanation

    A LEFT (outer) JOIN keeps all left rows. An INNER JOIN keeps only matching pairs, a RIGHT JOIN keeps all right rows, and a CROSS JOIN pairs every row with every row.

  8. Question 8

    Easy

    What is the difference between WHERE and HAVING?

    1. AHAVING filters rows before grouping; WHERE filters groups
    2. BThey are interchangeable in every query
    3. CWHERE can use aggregates such as SUM directly; HAVING cannot
    4. DWHERE filters rows before grouping; HAVING filters groups after aggregationAnswer

    Explanation

    WHERE runs on individual rows before GROUP BY, so it cannot use aggregates. HAVING runs on the groups afterwards, so conditions like HAVING COUNT(*) > 5 go there.

  9. Question 9

    Medium

    Table Emp(id, name, salary). Which query returns the second highest distinct salary?

    1. ASELECT MAX(salary) FROM Emp WHERE salary > (SELECT MAX(salary) FROM Emp);
    2. BSELECT salary FROM Emp ORDER BY salary DESC LIMIT 2;
    3. CSELECT MAX(salary) FROM Emp WHERE salary < (SELECT MAX(salary) FROM Emp);Answer
    4. DSELECT MIN(salary) FROM Emp;

    Explanation

    The subquery finds the top salary, and the outer MAX picks the largest salary below it. ORDER BY ... LIMIT 2 returns two rows, and both could be the same top salary.

  10. Question 10

    Medium

    Relation R(A, B, C, D) has the functional dependencies A → B, B → C and C → D. What is the candidate key of R?

    1. AAB
    2. BB
    3. CABCD
    4. DAAnswer

    Explanation

    From A we get B, then C, then D, so A determines every attribute. Nothing determines A, so it is in every key, and A alone is minimal. AB and ABCD are superkeys but not minimal.

  11. Question 11

    Medium

    R(A, B, C, D, E) has the functional dependencies A → B, B → C and CD → E. What is the closure {A, D}⁺?

    1. A{A, B, C, D}
    2. B{A, D}
    3. C{A, B, C, D, E}Answer
    4. D{A, B, D}

    Explanation

    Start with {A, D}. A → B adds B, B → C adds C, and now C and D together give E through CD → E. The closure is {A, B, C, D, E}.

  12. Question 12

    Medium

    A transaction reads a value written by another transaction that has not committed yet. What is this problem called?

    1. ANon-repeatable read
    2. BPhantom read
    3. CDirty readAnswer
    4. DLost update

    Explanation

    Reading uncommitted data is a dirty read: if the writer rolls back, the reader used a value that never officially existed.

  13. Question 13

    Medium

    In the SQL standard, which isolation level prevents dirty reads but still allows non-repeatable reads?

    1. ARead committedAnswer
    2. BRead uncommitted
    3. CRepeatable read
    4. DSerializable

    Explanation

    Read committed only lets a transaction see committed data, but a row read twice can change in between if another transaction commits. Repeatable read and serializable prevent that too.

  14. Question 14

    Medium

    Table T has 10 rows, and its column bonus is NULL in 3 of them. What does SELECT COUNT(bonus) FROM T; return?

    1. A10
    2. B7Answer
    3. C3
    4. DNULL

    Explanation

    COUNT(column) counts only non-NULL values, so it returns 7. COUNT(*) would count all 10 rows.

  15. Question 15

    Easy

    What is the main cost of adding an index on a column?

    1. ASlower inserts and updates, plus extra storageAnswer
    2. BSlower SELECT queries that filter on that column
    3. CDuplicate rows being deleted automatically
    4. DNULLs no longer being allowed in the column

    Explanation

    An index speeds up lookups, but every insert, update or delete must also update the index, and the index takes space.

  16. Question 16

    Medium

    Table Enrolment has the composite primary key (StudentID, CourseID), and the column StudentName depends only on StudentID. Which is the lowest normal form this table fails?

    1. A1NF
    2. B3NF
    3. CBCNF
    4. D2NFAnswer

    Explanation

    StudentName depends on part of the key, which is a partial dependency, and 2NF forbids exactly that. The fix is a separate Student(StudentID, StudentName) table.

  17. Question 17

    Hard

    R(A, B, C) has the functional dependencies AB → C and C → B. Which statement is true?

    1. AR is in BCNF
    2. BR is not in 2NF
    3. CR is in 3NF but not in BCNFAnswer
    4. DR is not in 3NF

    Explanation

    The candidate keys are AB and AC, so every attribute is prime. C → B breaks BCNF because C is not a superkey, but 3NF allows it because B is a prime attribute.

  18. Question 18

    Medium

    Orders(id, customer, amount) has the rows (1, 'Asha', 500), (2, 'Ravi', 300), (3, 'Asha', 700), (4, 'Meena', 200) and (5, 'Ravi', 400). Which customers does this query return?

    SELECT customer FROM Orders
    GROUP BY customer
    HAVING SUM(amount) > 600;
    1. AAsha and RaviAnswer
    2. BAsha only
    3. CAsha, Ravi and Meena
    4. DRavi only

    Explanation

    The totals are Asha 1,200, Ravi 700 and Meena 200. HAVING keeps the groups above 600: Asha and Ravi.

  19. Question 19

    Easy

    Which SQL keyword removes duplicate rows from a query's result?

    1. AUNIQUE
    2. BDISTINCTAnswer
    3. CGROUP
    4. DONLY

    Explanation

    SELECT DISTINCT returns each different row once. UNIQUE is a constraint on a column, not a query keyword for de-duplicating results.

  20. Question 20

    Easy

    Table A has 4 rows and table B has 5 rows. How many rows does A CROSS JOIN B return?

    1. A20Answer
    2. B9
    3. C5
    4. D4

    Explanation

    A cross join pairs every row of A with every row of B: 4 × 5 = 20 rows.

  21. Question 21

    Hard

    Students(id) has the ids 1, 2, 3 and 4. Marks(student_id, marks) has the rows (1, 80), (1, 75) and (3, 90). How many rows does this query return?

    SELECT * FROM Students s
    LEFT JOIN Marks m ON s.id = m.student_id;
    1. A4
    2. B3
    3. C5Answer
    4. D12

    Explanation

    Student 1 matches two marks rows (2 rows), student 3 matches one (1 row), and students 2 and 4 match none but are kept with NULLs (1 row each). Total = 5.

  22. Question 22

    Easy

    A bank transfer debits one account and credits another. The server crashes after the debit but before the credit. Which ACID property makes sure the debit is undone?

    1. AConsistency
    2. BIsolation
    3. CDurability
    4. DAtomicityAnswer

    Explanation

    Atomicity means a transaction happens completely or not at all, so recovery rolls back the half-done transfer. Durability is about keeping committed changes.

  23. Question 23

    Hard

    Is this schedule conflict serializable? R1(X), W2(X), W1(X) (R1(X) means transaction 1 reads X; W2(X) means transaction 2 writes X.)

    1. AYes, it is equivalent to running T1 then T2
    2. BNo, its precedence graph has a cycleAnswer
    3. CYes, it is equivalent to running T2 then T1
    4. DYes, every schedule of two transactions is

    Explanation

    R1(X) comes before the conflicting W2(X), giving an edge T1 → T2. W2(X) comes before the conflicting W1(X), giving T2 → T1. The cycle means no serial order matches, so it is not conflict serializable.

companies
222
rounds described
1,432
pieces of advice
3,771

Your next drive is closer than you think.

Start with the 15-minute mixed test: 13 questions that show where you stand in every section.