your image

MySQL UPDATE Statement

quackit
Related Topic
:- MYSQL

MySQL UPDATE Statement

 

The UPDATE statement is used to update data in a database table. When using the UPDATE statement, you specify the table name, the field to be updated, and its new value.

 

UPDATE sakila.actor
SET last_name = 'Flanders'
WHERE actor_id = 204;

The above statement updates record 204 to have a last name of "Flanders". This results in "Marge Rubble" becoming "Marge Flanders".

If we run a SELECT statement before and after the UPDATE statement, here's the result.

Before:

After:

Update Multiple Fields

You can update multiple fields by using a comma to separate each field assignment. Like this:

 

 
UPDATE sakila.actor
SET first_name = 'Margarine', last_name = 'Burns'
WHERE actor_id = 204;

Result:

The examples on this page use the Sakila sample database.

Comments