DB2- Avoid Select Column Before do UPDATE

We do not have to retrieve data first and manipulate it before executing the SQL UPDATE.

Avoiding that work requires an extra call to DB2.

Below example dynamically retrieve a row, and update the Column value.

suppose an employee is to be given a 10% raise. You could select the employee’s salary, add 10% to the value, and then use the new value in an SQL UPDATE statement. Instead, the Update statement should look like this:
UPDATE EMP
SET SALARY = SALARY * 1.1
WHERE EMPNO = 1000

The way coding above is good practice.

Advertisements

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.