Allowable Characters

advertisement
Allowable Characters
The first character of a name must be a Letter (a-z or A-Z), be aware
that SQL server attaches special meaning to names that begin with @
or #. Later characters can be any combination of Letters, Digits, or
special characters.
Case Sensitivity
Always be consistent with case. Identifiers in SQL Server are dependent
on the default collation of the database. If the default collation is caseinsensitive, then t equals T. If the collation is case-sensitive then t does
not equal T. The collation may change in the future, so it is best to
keep the use of case consistent.
Abbreviations
Naming should be descriptive and abbreviations should be kept to a
minimum, however the following common abbreviations can be used:
GL – General Ledger
DIV - Division
SCR - Source
ACT - Account
DESC - Description
YTD – Year To Date
GRP - Group
MKT - Marketing
BUD - Budget
QTR - Quarter
CAL – Calendar
Reserved Words
Reserved words should not be used as object names; see SQL Server
Books Online for the current and future list of reserved Keywords. To
improve compatibility and upgrade options ensure that reserved words
for other major RDBMS are not being used.
Database Names, File Names and File Paths
The database name should accurately reflect the database content and
or function.
File names must match the database name.
Tables and Views
Staging tables have ‘tmp’ prefixed to the table name.
Production tables should not have a prefix.
Table naming use camel casing, the prefix information is always lower
case.
Do not user “_” or “ “ in table names.
Example tmpSummaryActuals is the staging table. SummaryActuals is
the production table
Table names should be plural nouns. The use of a singular noun as a
table name can give the impression that the set contains only one row.
Views are very similar to tables and the same naming convention
should apply. There are two exceptions:
1) Views can be a combination of multiple tables based on a join.
In this case consider combining the names of both the base
tables.
2) Views can summarize data from existing base tables in the form
of reports. The name should reflect the purpose of the report.
Columns
The Column names should be descriptive to their purpose, meaningful
and natural.
Example column names,
TmpInventoryTotals table could have the following coloumn names:
TransactionDate, ProductCode, StockOnHand
Prepositions, conjunctions and articles should be used sparingly in
column names.
Do not prefix or suffix additional information to a column name, such
as variable type information, or table name.
Column names should be consistent through the database. Do not
change the name of columns across tables, for example you shouldn’t
have tables with column names like EmpPhoneNumber,
CustPhoneNumber, phone numbers are the same for employees and
customers so the column name should reflect that.
Stored Procedures
Stored Procedures always do some form of work / action. The name
should describe the action they perform. Use verb plus object form
when naming stored procedures.
User stored procedures should be prefixed with ‘usp_’, for example:
usp_UpdateEmployees
usp_DeleteEmployees
usp_InsertEmployees
Do not prefix stored procedures with “sp_” unless you are storing the
stored procedure in the Master database. If you call a stored procedure
prefixed with “sp_”, SQL server always looks for this procedure in the
master database. Only after checking in the master database (if not
found) will it search the current database.
User defined Functions
Use the same convention as applied for stored procedures, appending
“udf_” to the beginning of the name.
Code Format:
Your eyes need a way to pick out structure words from user defined
words in a program text. The following code format recommendations
use the following visual cues; layout on the page and capitalization.





Indentation is always done as four spaces instead of a tab
character.
Each sub-block within a code block is indented four spaces from
its parent.
Transact-SQL Keywords are all uppercase.
All Schema objects use the same case as the database design.
All Scalars in lowercase
Example:
CREATE PROCEDURE Usp_Myproc
As
Declare @myvar int,
@myvar2 varchar(25)
Set @myvar = 1
WHILE @myvar < 40
BEGIN
SELECT @myvar2 = Column1 FROM MyTable When Column2 =
@myvar
If @myvar2 = ‘SomeValue’
BEGIN
EXEC usp_SomeOtherProc @mycar2
END
Set @myvar = @mycar + 1
END
Download