You are on page 1of 1

Internal

GENISYS Configurator : .SQL Coding Guidelines

SQL Coding Guidelines


UNION:
Use UNION ALL instead of UNION unless you want to eliminate duplicate

Selected rows:
Avoid using SELECT * FROM table. Define the column names instead.

Duplicate rows:
Avoid using DISTINCT if you can tolerate having duplicate rows returned by a query.

Outer join:
Review the use, especially outer joins should not be required between a child and master table.
Don't mix LEFT and RIGHT OUTER JOIN in the same query.

Use bind variables:


Don’t use constants in the where condition, use bind variables this will reduce repeated parsing.

Use SELECT... BULK COLLECT INTO ... FROM ... only when you are sure that the result set
will be of a reasonable size, otherwise, use an explicit cursor and fetch with the LIMIT clause.

Search limiting:
Use rownum to limit search after finding "n" rows

Views:
Don’t use views unless you require all the tables of the view in the query. Use base tables
instead, if you just need to access a few columns/tables only.

Upper:
Don’t use upper on columns which are indexed. If these are indexed, then upper will not enable
index to be used.

Wild card:
Use this only in cases where required, don’t use LIKE without a wild card character. Don’t use it
to compare full value supplied.

Sorting & group:


Review the sort and groupby criteria, and use this only if required.
Normally display grids support sorting, so it can be done in Presentation layer.

Procedural logic:
Long running sqls and code must be developed as pl/sql codes don’t write a single query which
runs for long time.

Conditional retrieval:
Don’t use nested selects, instead embed such logic in pl/sql, so that if...then...else conditions
can be used and access can be optimized.

Datatype:
Respect the data type stored in the table, don’t do too many conversions in the query (for
example char to number, date to char etc..).

CMC Limited For Internal Use Only Page 1 of 1


GENISYS Configurator Date: 28th Nov, 2007 Version No: 1.0

You might also like