MySQL + SQL · Lesson 53
Safe UPDATE and DELETE Practices
Avoiding Accidents
UPDATE/DELETE without WHERE can wipe a whole table. MySQL has a safe update mode to block such risky commands.
Safe Update Mode
SET SQL_SAFE_UPDATES = 1;
-- now this is BLOCKED (no WHERE with a key):
DELETE FROM students; -- Error 1175
-- allowed (uses key column):
DELETE FROM students WHERE roll_no = 5;
Safe Habits
- Run a SELECT with the same WHERE first to preview affected rows.
- Wrap risky changes in a transaction so you can ROLLBACK.
Summary
- SQL_SAFE_UPDATES blocks UPDATE/DELETE without a key-based WHERE.
- Preview with SELECT and use transactions to stay safe.