Purpose: Guidelines For SQL Objects
Purpose: Guidelines For SQL Objects
6. One must avoid use of cursors. Cursors should be used as less as possible.
7. All SQL keywords (e.g., IF, SELECT, etc.) must typed in upper case only.
8. Try to avoid IN clause when query is like - Select * from table1 where field1
IN (Select field1 from table2). Instead of IN clause use INNER JOIN.
9. Try to avoid NOT IN clause when query like - Select * from table1 where
field1 NOT IN (Select field1 from table2). Instead of IN clause use LEFT
OUTER JOIN or RIGHT OUTER JOIN.
10. Write IF EXISTS or DROP Statement before writing any STP, UDF or any
database object script.
11. Try to avoid the use of LIKE clause because it affects performance.
12. DTS Packages will be used for file upload or lengthy processes instead of
writing a code from program.
13. UDF will be used for calculating a value and value will be stored in a variable.
This type of UDF will not be called in Query for avoiding the query
performance.
14. If UDF is returning recordset or table type then UDF will be used in JOIN only
not in directly SELECT clause or WHERE clause.
15. Dont use Decimal, float, real data type instead of these use Numeric (?,?).
16. Use Varchar Data type for String Data.
17. Primary Key name must be always like this PK_TableName_FieldName
18. Foregin Key name must be always like this
FK_TableName_FieldName_RefrenceTableName_RefrenceFieldName
19. Check Constraint name must be like this CK_TableName_FieldName.