Databases · SQL Operations
INSERT, UPDATE and DELETE Safely
Cheat sheet · https://pcornel.dk/topic.php?topic=6166
Answer
Safe data changes: preview with SELECT, run inside a transaction, check affected rows, keep a backup or undo path, and batch large changes.
Remember
No WHERE = every row. Large deletes lock and bloat — batch them. Some clients auto-commit; disable or wrap in BEGIN.
First checks
SELECT count(*) FROM t WHERE <cond>;— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
Verify in this order
preview → transaction → change → verify → commit
Where it usually breaks
An UPDATE without WHERE changes every row.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6166