MySQL UPDATE

MySQL UPDATE statement can be used to update the values of the columns of the existing rows in a table.

MySQL UPDATE Statement Syntax

Below is the Basic Syntax of MySQL UPDATE Statement.

MySQL UPDATE Statement Examples

To understand MySQL UPDATE statement with examples, let us create a Customer Table with sample data as shown in the following image by execute the following script.

mysql-update-customers-demo-table

Example 1 : MySQL UPDATE Statement to Update One Column Value

This example demonstrates how we can update one column value using MySQL UPDATE Statement. We can execute the below MySQL UPDATE statement to update the Customer FirstName from Michael to Roger for the Customer whose CustomerId is 1.

RESULT:
mysql-update-customers-example1

Example 2 : MySQL UPDATE Statement to Update Multiple Column Values

This example demonstrates how we can update one column value using MySQL UPDATE Statement. We can execute the below MySQL UPDATE statement to update the Customer FirstName from James to Oliver and LastName from Cameron to Heaviside for the Customer whose CustomerId is 2.

RESULT:
mysql-update-example-2

Example 3: MySQL UPDATE Statement to Update a Column Value for all the ROWS

If we don’t specify the WHERE clause in the MySQL UPDATE statement it will update all rows of the Table. We can execute the below MySQL UPDATE statement to update the LastName of all the customers as Lewis.

RESULT:
mysql-update-example-3

Leave a Reply

Your email address will not be published. Required fields are marked *