Home > Database > Mysql Tutorial > body text

How to use UPDATE statement in SQL

WBOY
Release: 2023-06-02 21:13:24
forward
7866 people have browsed it

SQL UPDATE statement
The Update statement is used to modify data in the table. The syntax is as follows:

UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
Copy after login

"Person" Table:

LastName    FirstName    Address            City
Gates       Bill         Xuanwumen 10       Beijing
Wilson                   Champs-Elysees
Copy after login


Update a column in a row

UPDATE Person SET FirstName = "Fred" WHERE LastName = "Wilson"
Copy after login

Result:

LastName    FirstName    Address            City
Gates       Bill         Xuanwumen 10       Beijing
Wilson      Fred         Champs-Elysees
Copy after login

Note: This example adds firstname to the person whose lastname is "Wilson".

Update several columns in a row

UPDATE Person SET Address = "Zhongshan 23", City = "Nanjing" WHERE LastName = "Wilson"
Copy after login

Result:

LastName    FirstName    Address            City
Gates       Bill         Xuanwumen 10       Beijing
Wilson      Fred         Zhongshan 23       Nanjing
Copy after login

Note: This example will modify the address (address ), and add the city name (city).

The above is the detailed content of How to use UPDATE statement in SQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template