Update data using SQL

Last updated: April 26, 2023

To update record or data UPDATE query is used.

Syntax:

UPDATE table_name

SET column1 = new_value1, column2 = new_value2, column3 = new_value3 ........

WHERE condition

According to this course, we used contact table of account database. First show database's data then update.

SELECT * FROM contact;
fetch all data from table

Where unfortunately last two rows id is 2. Here, we are seeing that name field are unique. So that we can update id using name.

Using SQL update id = 13 where name = "James":

UPDATE contact 
SET id = 13 
WHERE name = "James";
Using SQL update id = 13 where name = "James"

Now show again all data from contact table:

SELECT * FROM contact;

Using SQL update id = 14 where name = "Nenson Lio" and mobile number = "017934721":

UPDATE contact 
SET id = 14 
WHERE name = "Nenson Lio" AND mobile = "017934721";

Now show again all data from contact table:

SELECT * FROM contact;

Related post