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.

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading