Anda di halaman 1dari 3

Purpose

The purpose of this document is to describe the coding standards to be followed


while coding.

Guidelines for SQL Objects:


1. There must be a comment block at the beginning of each Store procedure,
Function, Trigger and View. E.g.,
/*
* Object Name: _
* Author Name: _
* Created Date: _
* Description: _
*
* Revision Information:
* Date Author Description
* ----- ------- ------------
*_ _ _
*_ _ _
*/

Check Guidelines for general application

2. On successful completion of the stored procedure, it should return 0 and non-


zero value in case of any error occurred.

3. Following naming convention must be followed for defining any database


object:

Database Object Prefix


User Defined Data Type Udt
User Defined Function Fn
ModuleAbbrivation
Index Idx
Store Procedure Stp
ModuleAbbrivation
Table Tbl
ModuleAbbrivation
e.g. TblQBGroup,
QB Query
Builder
Trigger Trg
ModuleAbbrivation
View Vw
ModuleAbbrivation
SQL-Data type:
Binary Bin
Image Img
Varbinary VBin
Bit Bit
Char Chr
Nchar NChr
Datetime Dt
Smalldatetime Sdt
Bigint Bint
Int Int
Smallint Sin
Tinyint Tin
Decimal Dec
Float Fl
Money Mo
Numeric Num
Real Rl
Smallmoney Smo
Timestamp Tms
Uniqueidentifier Uid
Sql_variant Var
Ntext Ntxt
Nvarchar Nvc
Text Txt
Varchar Vc

4. Transaction block must be used if any data modification statement is used


during SQL Statement block.

5. One must avoid use of dynamic queries.

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.