The UPDATE
statement is used to modify the value(s) in existing records in a table.
Set the color of the Volvo to 'red':
UPDATE cars
SET color = 'red'
WHERE brand = 'Volvo';
UPDATE 1
Which means that 1
row was affected by the UPDATE
statement.
Note: Be careful with the WHERE
clause, in the example above ALL rows where brand = 'Volvo' gets updated.
To check the result we can display the table with this SQL statement:
Be careful when updating records. If you omit the WHERE
clause, ALL records will be updated!
Without the WHERE
clause, ALL records will be updated:
UPDATE cars
SET color = 'red';
UPDATE 4
Which means that all 4
row was affected by the UPDATE
statement.
To check the result we can display the table with this SQL statement:
To update more than one column, separate the name/value pairs with a comma ,
:
Update color and year for the Toyota:
UPDATE cars
SET color = 'white', year = 1970
WHERE brand = 'Toyota';
UPDATE 1
Which means that 1
row was affected by the UPDATE
statement.
To check the result we can display the table with this SQL statement:
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!