- The SQLCODE must be checked after every SQL statement. The SQL for beginners is highly useful course, if you would like to know more.
- Every program must include SQLCA(only once), and DCLGEN for each table
- Every program must have abend routine. In this routine make sure to use,SQLCODE and SQLSTATE to display
- Never code SELECT * in program. It takes unnecessary I/O, and in turn more CPU usage
- Make sure all Nullable columns must use Indicator variable along with host variable
- Better use scalar functions, when you expect nulls – as below example
- For example:
SELECT IFNULL(AVG(SALARY), 0) FROM EMP WHERE WORKDEPT = 'XYZ'
- Minimize the no of times Opens or Close a cursor
- During SELECT,INSERT and UPDATE always use counters in Program. When problem comes, we can easily trace back to root.
- SQLERRD(3), it will be updated, when INSERT,UPDATE and DELETE takes place. THIS IS NOT POPULATED WHEN MASS DELETES OCCURRED WITHOUT WHERE CLAUSE. For example deletes due to DELETE CASCADE.
More resources to read