SQL UPDATE
Change values in existing rows.
Syntax
UPDATE t SET col = value, … WHERE condition;
Without WHERE, every row changes. Run the WHERE as a SELECT first.
Example
Query (on the shop database used in the SQL course)
UPDATE products SET price = ROUND(price * 1.05, 2) WHERE category = 'Books'; SELECT name, price FROM products WHERE category = 'Books';
Result
| name | price |
|---|---|
| Python Crash Course (book) | 47.25 |
| Deep Learning (book) | 93.45 |
| SQL Pocket Guide | 26.25 |
3 rows
Related
Learn it step by step in the free lesson Changing Data, with exercises that check your queries.