MySQL Update


The UPDATE SET syntax is used to modify the data in the update data table.

grammar:

UPDATE tb_name SET column1 = new_value1, column2 = new_value2, ... WHERE conditions

This syntax updates the value of column1 in the records that match the WHERE condition in the data table to new_value1, the value of column2 to new_value2, and so on. If the WHERE condition is omitted, the column values ​​for all the records in the table are updated.

example:

UPDATE user SET email = 'jack@yahoo.com' WHERE uid = 3

Before Update

uid username password email regdate
3 Jack 0193686a35e4de85ee3f2ff0567adf490 jack@gmail.com 1278061380

After Update

uid username password email regdate
3 Jack 0193686a35e4de85ee3f2ff0567adf490 jack@yahoo.com 1278061380

UPDATE expression

The UPDATE syntax allows SETs to be followed by an expression.

Example 1:

UPDATE article SET page_view = page_view + 1 WHERE id = 123

This example allows an article with an page_view of 123 to be incremented by 1 when it is clicked to read.


Example 2:

UPDATE persondata SET age = age * 2, age = age + 1

The example SET is followed by two expressions: age = age * 2 (age doubled), age = age + 1 (plus 1). In the case of such multiple expressions, they are executed from left to right.




Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook