In this tutorial, you will learn how to update existing data in a SQL database. Let’s see –
Here is some dummy existing data of the users table, and we will see how we can update one of those.

SQL query syntax for updating data
UPDATE `table_name` SET column1='new value', column2='new value' ... WHERE condition;
table_name | Which table’s data do you want to update? In my case table name is – users |
column1 | Name of the column whose value want to update. |
column2 | You can update multiple columns by separating them with a comma. |
condition | You have to define the condition, otherwise, it will update all the rows. |
Example with explanation
UPDATE `users` SET `name`='Rahul' WHERE `user_id`=1;
UPDATE `users` | update the users table. |
SET `name`=’Rahul’ | set Rahul in the name column. |
WHERE `user_id`=1 | Update the row in which the user_id column is equal to 1 |
Result: after updating

Example of updating multiple columns
UPDATE `users` SET `name`='Ritesh', `email`='[email protected]' WHERE `user_id`=3;
