In MySQL, the UPDATE statement is used to update existing records in a table.
UPDATE Syntax
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
In the above syntax, WHERE clause specifies which row or rows will be updated,if we don't define WERE clause then all records of the table will be updated.
We have a table "employee" as below:
employee
id first_name salary country
.......................................................
1 John 10000 Canada
2 Chris 20000 Canada
3 Max 30000 Korea
4 Jenny 25000 Canada
UPDATE Example
The below statement will update "country" for the employee "John" in the "employee" table:
UPDATE employee
SET country='London', salary='15000'
WHERE first_name='John';
Result
id first_name salary country
.......................................................
1 John 15000 London
2 Chris 20000 Canada
3 Max 30000 Korea
4 Jenny 25000 Canada
If we remove the WHERE clause from the above statement as below then all the records in the table "employee" table will be updated
UPDATE employee
SET country='London', salary='15000';
Result
id first_name salary country
.......................................................
1 John 15000 London
2 Chris 15000 London
3 Max 15000 London
4 Jenny 15000 London
Hope this will help you :)
0 Comment(s)