DB2- How to write Best SQL Queries

Teradata Jobs
Teradata Jobs

The following SQL checklist will help to review SQL Queries.

  1. Check for by mistake any inner join is coded as outer-join
  2. Check all union statements, is it really needed, or we can go with UNION ALL
  3. Check for NULLABLE columns, if NULL value comes, we need to handle -305 errors
  4. Check for Select statement, is all the columns absolutely needed
  5. Check for ALL aggregate functions, handling NULL values properly
  6. Check for DISTINCT statements. Always better either go with Sub-query or Co-related sub-query or Group by
  7. Check for each CASE statement ELSE is coded or not.
  8. Check for NOT logic. It works as non-index scan

Keep reading for more checklist in my next post.

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.