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.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n

💻 Live Code Editor

Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.
Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.

💻 Live Code Editor

Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें. Agar load na ho to naye tab mein kholें.