通过UPDATE命令,可更改现有行的列值。

示例

  1. 示例数据库上执行如下语句,查询经理当前薪水:

    SELECT ename, sal FROM emp WHERE job = 'MANAGER';

    返回结果如下:

     ename |   sal
    -------+---------
     JONES | 2975.00
     BLAKE | 2850.00
     CLARK | 2450.00
    (3 rows)
  2. 执行如下语句,为每个经理加薪10%:

    UPDATE emp SET sal = sal * 1.1 WHERE job = 'MANAGER';

    查询加薪后的经理薪水:

    SELECT ename, sal FROM emp WHERE job = 'MANAGER';

    返回结果如下:

     ename |   sal
    -------+---------
     JONES | 3272.50
     BLAKE | 3135.00
     CLARK | 2695.00
    (3 rows)