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?

  1. A. 2 rows, sum 200
  2. B. 3 rows, sum 300
  3. C. 4 rows, sum 400
  4. 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

Exams that ask this topic