IBM Books

SQL Getting Started


Changing Data

Use the UPDATE statement to change the data in a table. With this statement, you can change the value of one or more columns in each row that satisfies the search condition of the WHERE clause.

The following example updates information on the employee whose ID is 410:

     UPDATE PERS
        SET JOB='Prgmr', SALARY = SALARY + 300
        WHERE ID = 410

The SET clause specifies the columns to be updated and provides the values.

The WHERE clause is optional and it specifies the rows to be updated. If the WHERE clause is omitted, the database manager updates each row in the table or view with the values you supply.

In this example, first the table (PERS) is named, then a condition is specified for row that is to be updated. The information for employee number 410, has changed: the employee's job title changed to Prgmr, and the employee's salary increased by $300.

You can change data in more than one row by including a WHERE clause that applies to two or more rows. The following example increases the salary of every salesperson by 15%:

     UPDATE PERS
        SET SALARY = SALARY * 1.15
        WHERE JOB = 'Sales'


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]