Chapter 10 of 10All chapters
Chapter 10 of 10
Changing data
INSERT, UPDATE, DELETE and transactions.
The dangerous clause
UPDATE and DELETE without a WHERE clause change every row in the table. Running the SELECT version of the condition first is a habit worth keeping for life.
- A transaction groups statements so they all apply or none do.
- COMMIT makes the change permanent; ROLLBACK undoes it.
Safety
Never build a query by joining strings with user input, which is how SQL injection happens. Use parameters and let the driver handle escaping.