CS FundamentalsVery hardGATE CS · SQL
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 this query return?
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 this query return?
WITH RECURSIVE reach(node, hops) AS ( SELECT 'A', 0 UNION SELECT r.dst, hops + 1 FROM reach JOIN Route r ON r.src = reach.node WHERE hops < 2) SELECT COUNT(*) FROM reach;
- A. 5
- B. 4
- C. 3
- D. 6
Correct answer: A. 5
Rows: (A,0); hop 1: (B,1), (C,1); hop 2: from B → (C,2), (D,2) and from C → (D,2) again. UNION drops the duplicate (D,2) but keeps (C,1) and (C,2) as different rows, so 5 (UNION ALL would give 6, distinct nodes only 4).
More DBMS and SQL questions
- Table Acct(no, branch, bal) rows: (101, 'Agra', 500), (102, 'Agra', 1500), (103, 'Bhopal', 700), (104, 'Bhopal', 700), (105, 'Cuttack'…
- Which statement about snapshot isolation (SI) is correct?
- R(A, B) has 300 tuples and S(B, C) has 50 tuples, where S.B is the primary key of S and R.B is a foreign key referencing it (NOT NULL)…
- Table P(x) rows: (1), (2), (2), (3), (NULL). Table Q(x) rows: (2), (3), (3), (NULL), (4). What does this query return? sql SELECT COUNT()…
- R has 500 tuples in 50 blocks and S has 4000 tuples in 200 blocks. With only enough memory for one block of each relation, how many block…
- Under BOTH wait-die and wound-wait deadlock prevention, which transaction can be rolled back when a lock conflict occurs?