UPDATE Record — SQL Technical Interview Questions & Answers
UPDATE Record
UPDATE Record
- UPDATE students SET marks = 80 WHERE roll = 12; changes matching rows. SET is what to change. WHERE is which rows. Without WHERE, every student becomes 80. Workbench safe-updates mode blocks UPDATE/DELETE without a key — that is a seatbelt, not a bug.
- Preview: SELECT * FROM students WHERE roll = 12; then UPDATE. In a transaction: START TRANSACTION; UPDATE …; SELECT to check; COMMIT or ROLLBACK.
- Trap: WHERE name = 'Asha' when two Ashas exist. Use the PRIMARY KEY. Trap: marks = marks + 1 without WHERE.
- On the example next to this theory: UPDATE Record — uPDATE changes existing rows — always scope with WHERE.
Technical Interview Tip: UPDATE … SET … WHERE roll = 12. Never skip WHERE.
Code Examples for UPDATE Record
UPDATE Record — sample query
CREATE TABLE products (id INTEGER PRIMARY KEY, name TEXT, price REAL);
INSERT INTO products VALUES (1, 'Mouse', 499);
UPDATE products SET price = 449 WHERE id = 1;
SELECT * FROM products;UPDATE Record — uPDATE changes existing rows — always scope with WHERE.
How to Explain UPDATE Record to an Interviewer
Write an UPDATE.
UPDATE students SET marks = 80 WHERE roll = 12;
What if you omit WHERE?
Every row changes Often a disaster