Reading data is only half the job — INSERT, UPDATE, and DELETE are how data enters and changes in your tables. One golden rule runs through all of them: never forget the WHERE clause.
Key Points
- INSERT INTO t (col1, col2) VALUES (v1, v2); — multiple rows in one statement with comma-separated tuples
- INSERT INTO t SELECT … copies data between tables
- UPDATE t SET status='shipped' WHERE id=101; — WHERE is critical
- DELETE FROM t WHERE created_at < '2024-01-01'; removes matching rows
- Upsert: INSERT … ON DUPLICATE KEY UPDATE handles insert-or-update logic
- Safety net: run SELECT with the same WHERE first, and use transactions
.png)