UPDATE modifies rows; DELETE removes rows. Always use WHERE!
TRUNCATE
Removes all rows faster than DELETE. Resets auto-increment.
Transactions
Use START TRANSACTION, COMMIT, ROLLBACK for atomicity.
UPDATE modifies rows; DELETE removes rows. Always use WHERE!
Removes all rows faster than DELETE. Resets auto-increment.
Use START TRANSACTION, COMMIT, ROLLBACK for atomicity.
UPDATE users SET email = "new@mail.com" WHERE id = 1; UPDATE products SET price = price * 1.10 WHERE category = "Electronics"; DELETE FROM users WHERE status = "inactive"; TRUNCATE TABLE logs;
-- Update single row UPDATE users SET city = "Multan" WHERE id = 1; -- Update multiple columns UPDATE users SET name = "Alice Khan", city = "Lahore" WHERE email = "alice@example.com"; -- Update with condition UPDATE users SET status = "active" WHERE age >= 18; -- Delete specific row DELETE FROM users WHERE id = 5; -- Delete older than 2024 DELETE FROM users WHERE created_at < "2024-01-01"; -- Verify no orphans SELECT COUNT(*) FROM users;
50% off all Clearance products.
UPDATE products SET price = price * 0.50 WHERE category = "Clearance";
UPDATE without WHERE?
All rows are updated.
Ensures atomicity � all changes succeed or none do, preventing inconsistent states.