DML & Transactions · Question 17 · Hard

DML & Transactions question 17

Table Account:
acc_no | holder | balance
101 | Farah | 5000
102 | Gopal | 12000
103 | Hema | 800
104 | Imran | 7000

The UPDATE is meant to raise only balances below 1000 to 1000. What does the SELECT return afterwards?

UPDATE Account
SET balance = CASE WHEN balance < 1000 THEN 1000 END;
SELECT COUNT(*) FROM Account WHERE balance IS NULL;
  1. 0
  2. 3
  3. 1
  4. 4
Answer and explanation

Answer: B. 3

Explanation: There is no WHERE clause, so every row is updated. For the three rows with a balance of 1000 or more the CASE has no matching WHEN and no ELSE, so it returns NULL and their balances are overwritten with NULL. Adding ELSE balance, or a WHERE clause, would avoid this.

Previous: Table Wallet: user_name | points Lalit | 100 Mona | NULL Nitin | 50 Every user… · Next: Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…

Practise dml & transactions

Try a fresh set of dml & transactions questions with an explanation after every answer, free and without signing up: DML & Transactions practice. Or sit a full placement mock test.

More dml & transactions questions

More sql practice

SELECT, WHERE & ORDER BY · SQL Joins · Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge