SQLPathLab
Data Modification · Basic

UPDATE

updating existing rows

Overview

UPDATE changes existing rows, and WHERE controls the scope; omitting WHERE updates the whole table. A safe workflow runs SELECT with the same predicate, verifies target keys and row count, then performs UPDATE in a transaction and checks affected rows. SET may change several columns, but each value must satisfy types, constraints, and valid business-state transitions.

Basic syntax

UPDATE orders SET amount = 1300 WHERE id = 1;

Examples

UPDATE example

Change the amount of order id 1 to 1300, using the primary key to limit the update to one row.

Sample table

Table:orders
orders
idamount
1 1200
2 900
3 1500
4 700

Run result

orders
idamount
1 1300
2 900
3 1500
4 700

Common issues

Why run SELECT before changing data?

Checking the same WHERE predicate reveals an overly broad or missing condition before rows are changed.

What happens without WHERE?

UPDATE changes every row and DELETE removes every row, so verify scope before production use.

How can I reduce operational risk?

Use a transaction, inspect affected rows, commit only after verification, and keep recoverable backups for critical data.

Tags

CommonData modification

Was this explanation clear?