MySQL UPDATE Basic Update

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9

Example

Updating one row

UPDATE customers SET email='luke_smith@email.com' WHERE id=1

This query updates the content of email in the customers table to the string luke_smith@email.com where the value of id is equal to 1. The old and new contents of the database table are illustrated below on the left and right respectively:

enter image description here


Updating all rows

UPDATE customers SET lastname='smith'

This query update the content of lastname for every entry in the customers table. The old and new contents of the database table are illustrated below on the left and right respectively:

enter image description here

Notice: It is necessary to use conditional clauses (WHERE) in UPDATE query. If you do not use any conditional clause then all records of that table's attribute will be updated. In above example new value (Smith) of lastname in customers table set to all rows.



Got any MySQL Question?