The UPDATE
statement is used to modify existing records in a table.
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
table_name
: The table you want to update.SET
: Specifies the columns and new values.WHERE
: Limits which rows are updated (if omitted, all rows are updated).UPDATE cats
SET name = 'Whiskers'
WHERE cat_id = 3;
cat_id
3 to 'Whiskers'.UPDATE cats
SET name = 'Mittens', age = 5
WHERE cat_id = 2;
Explanation:
UPDATE cats
: Specifies the table to update.SET name = 'Mittens', age = 5:
Changes the name column to 'Mittens'
and the age
column to 5
.WHERE cat_id = 2
: Only updates the row where cat_id
equals 2
.