If we want to update the data in the PostgreSQL database, we can use the UPDATE To operate. The following is We can update one or more fields simultaneously. We can do it in Create the COMPANY table ( 下载 COMPANY SQL 文件 ), the data are as follows: The following example will be updated The results are as follows: As a result, the value of the salary field with id 3 in the COMPANY table has been modified. The following example will be updated at the same time The results are as follows: 5.19.1. Grammar ¶
UPDATE
Statement modifies the general SQL syntax for data:UPDATE table_name
SET column1 = value1, column2 = value2...., columnN = valueN
WHERE [condition];
WHERE
Any condition is specified in the. 5.19.2. Example ¶
runoobdb# select * from COMPANY;
id | name | age | address | salary
----+-------+-----+-----------+--------
1 | Paul | 32 | California| 20000
2 | Allen | 25 | Texas | 15000
3 | Teddy | 23 | Norway | 20000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall| 45000
7 | James | 24 | Houston | 10000
(7 rows)
COMPANY
The value of the salary field with id 3 in the table:runoobdb=# UPDATE COMPANY SET SALARY = 15000 WHERE ID = 3;
id | name | age | address | salary
----+-------+-----+------------+--------
1 | Paul | 32 | California | 20000
2 | Allen | 25 | Texas | 15000
4 | Mark | 25 | Rich-Mond | 65000
5 | David | 27 | Texas | 85000
6 | Kim | 22 | South-Hall | 45000
7 | James | 24 | Houston | 10000
3 | Teddy | 23 | Norway | 15000
salary
Fields and
address
Value of the field:runoobdb=# UPDATE COMPANY SET ADDRESS = 'Texas', SALARY=20000;
id | name | age | address | salary
----+-------+-----+---------+--------
1 | Paul | 32 | Texas | 20000
2 | Allen | 25 | Texas | 20000
4 | Mark | 25 | Texas | 20000
5 | David | 27 | Texas | 20000
6 | Kim | 22 | Texas | 20000
7 | James | 24 | Texas | 20000
3 | Teddy | 23 | Texas | 20000
(7 rows)