Wednesday, October 28, 2015

Naming conventions for SQL Server

Naming Conventions


Object Type
Synatax
Example
TableName
"tbl<TableName>"
tblEmployees
tblOrders
tblProducts
Primary Key Constraint
"PK_<TableName>"
PK_Employees
PK_Orders
PK_Products
Foreign Key Constraint
"FK_<TargetTable>_<SourceTable>".
FK_Orders_Employees
FK_Items_Products
Unique Key Constraint
"UQ_<TableName>_<ColumnName(s)>"
UQ_Employees_EmailID
UQ_Items_Code
Default Constraint
"DF_<TableName>_<ColumnName>"
DF_Employees_IsActive
DF_Employees_CreateDate
Check Constraint
"CHK_<TableName>_<ColumnName>"
CHK_Employees_Salary
CHK_Employees_DOB
User Defined Stored Procedures
User defined: "usp_" "usp_<Action>_<Object>"  System defined: "sp_"
usp_Insert_Employees
usp_View_EmployeeOrders
User Defined Functions
fn_<Action>
fn_CalulateTax
fn_CalculateAge
Views
"vw_<Result>"
vw_EmpOrderDetails
vw_SalesProductDetails
Triggers
"trg_<Action>_<TableName>"
trg_Ins_Employee
trg_Upd_Employee
trg_Del_Employee
Indexes
"IX_<TableName>_<Column(s)>”
IX_Employee_Name
IX_Employee_NameMobileNo