CS FundamentalsHardGATE CS (PYQ pattern)
ACC(id, bal): (1,100), (2,200), (3,300), (4,400). A row-level trigger AFTER UPDATE ON ACC FOR EACH ROW WHEN NEW.bal > 250 inserts (NEW.id, NEW.bal - OLD.bal) into LOG. Then UPDATE ACC SET bal = bal + 100 WHERE id >= 2 runs. How many LOG rows are created and what is the sum of the logged differences?
- A. 2 rows, sum 200
- B. 3 rows, sum 300
- C. 4 rows, sum 400
- D. 3 rows, sum 400
Correct answer: B. 3 rows, sum 300
The statement updates ids 2, 3, 4 to 300, 400, 500. The trigger fires once per row but its WHEN condition needs NEW.bal > 250, which is true for all three (300, 400, 500 > 250): 3 rows, each difference 100, sum 300. The condition tests the NEW value, so the row that went from 200 to 300 is included.
More DBMS and SQL questions
- K(a UNIQUE, b CHECK (b > 0)) is empty. These rows are inserted one by one, ignoring any row that violates a constraint: (1,5), (1,6)…
- G(g, x): (a,5), (a,7), (b,4), (b,4), (b,4), (c,20), (d,NULL), (d,1). How many groups does SELECT g FROM G GROUP BY g HAVING SUM(x) >…
- SALE(r, q, amt): (n,1,10), (n,2,30), (s,1,5), (s,2,5), (s,3,5), (e,1,50). View V is SELECT r, SUM(amt) AS tot, COUNT() AS c FROM SALE…
- A Grace hash join partitions both inputs into B - 1 partitions using one input page per partition plus one input buffer; in the probe…
- A table has 1,000,000 rows in 10,000 pages. An unclustered B+ tree index of height 3 costs 3 page reads to reach the first matching entry…
- A RAID 6 array has 10 disks, each sustaining 200 random I/Os per second. A small read costs 1 disk I/O and a small write costs 6 (read…