CS FundamentalsVery hardAmazon/Flipkart SQL round · GATE CS
Table Dept(did PRIMARY KEY) rows: (10), (20), (30). Table Emp(eid PRIMARY KEY, did REFERENCES Dept(did) ON DELETE CASCADE, mentor REFERENCES Emp(eid) ON DELETE SET NULL) rows: (1, 10, NULL), (2, 10, 1), (3, 20, 1), (4, 20, 3), (5, 30, 2), (6, 30, 4). What does this query return?
Table Dept(did PRIMARY KEY) rows: (10), (20), (30).
Table Emp(eid PRIMARY KEY, did REFERENCES Dept(did) ON DELETE CASCADE, mentor REFERENCES Emp(eid) ON DELETE SET NULL) rows: (1, 10, NULL), (2, 10, 1), (3, 20, 1), (4, 20, 3), (5, 30, 2), (6, 30, 4).
What does this query return?
DELETE FROM Dept WHERE did = 10; SELECT COUNT(*), COUNT(mentor) FROM Emp;
- A. 6, 4
- B. 4, 3
- C. 4, 4
- D. 4, 2
Correct answer: D. 4, 2
Deleting department 10 cascades to employees 1 and 2. Their deletion triggers ON DELETE SET NULL on mentor for employees 3 (mentor 1) and 5 (mentor 2). Remaining: 3, 4, 5, 6; only 4 and 6 still have mentors.
More DBMS and SQL questions
- Classify the schedule W3(A), R1(A), R2(B), R2(A), R3(B), C2, W1(B), R1(B), C1, C3 (Ci = commit of Ti) by the strongest property it…
- R(A, B) has 120 tuples and S(B, C) has 40 tuples, where B is a key of neither relation. What are the minimum and maximum possible numbers…
- R(A, B, C, D, E) has functional dependencies D → A, AB → CD, BE → C, BC → E. What is the closure {BC}⁺?
- A file of 5000 blocks is sorted by external merge sort with M = 21 buffer blocks (sorted runs of M blocks are created in pass 0, then (M −…
- Table Route(src, dst, cost) rows: ('A', 'B', 5), ('B', 'C', 4), ('A', 'C', 12), ('C', 'D', 3), ('B', 'D', 9), ('D', 'A', 2). What does…
- Table Acct(no, branch, bal) rows: (101, 'Agra', 500), (102, 'Agra', 1500), (103, 'Bhopal', 700), (104, 'Bhopal', 700), (105, 'Cuttack'…