Tuesday, November 3, 2015

DB2 TIPS


Select unknown values only




For performance reasons it is better to select as few columns as possible. The optimizer may choose techniques like Index-only access. Besides it makes the query easier to read and maintain.
In the following query selects five columns of table FOTB100. The first two columns are also used in the where-clause with “=”-predicates. So the values of these columns are no surprise and therefore it is not necessary to select these columns. So leave them out of the column-list.
 SELECT
        REK_NR
      , PE_TX_REF
      , ST_TS
      , ST
      , PRI
 INTO
       :REK-NR          OF FINTXSTH
     , :PE-TX-REF     OF FINTXSTH
     , :ST-TS              OF FINTXSTH
     , :ST                   OF FINTXSTH
     , :PRI                  OF FINTXSTH
FROM  FOTB100
 WHERE  REK_NR     = :REK-NR    OF FINTXST
   AND  PE_TX_REF  = :PE-TX-REF OF FINTXST



No comments:

Post a Comment