SQL Server Coding Standards -.. Part 1Introduction Everyone needs standards They promote cleaner code, better programming, and make it easier for teams of people to work together Standards are one of the foundations upon which computer science is built Coding standards (as I define. them) are the standards which specify how the object source code is written. This includes the format, documentation, structure of the object code, etc. Having good coding standards ensures that all object source code looks similar and allows different members of a team to More Quickly Understand The Object.
In my career I have worked in a number of different programming environments and have seen different types of standards for developing code. These have ranged from free (read non-existent here) to extremely rigid (variable names listed in a central document and specific formats for writing code). there have not been too many that I have really liked, and many of them were cumbersome. One thing that I have usually found, however, is that almost never are there DBA standards. I've been guilty of this Myself, WHEN i Managed Two Other DBAS, WHERE I HAD NOT FORMALLY SPELLED OUT How Object Code Was Written.
In my current job, we recently had doubled the size of the development staff and completed a large project. During the lull that followed, a couple developers were assigned the task of developing coding standards to ensure that all development efforts would look alike. The resulting WAS A Document and A Style That I real LIKED. After Viewing this document, I Started to develop My OWN Document Based On this Guide.
What Types of Standards Are Included? In developing my own coding standards, I decided to include the following items as they pertain to SQL source code. This would not apply to embedded SQL code which often exists in our Cold Fusion site (as well as many Web site. here is the list of items That Are Covered: Object Headers Variable Names Source Code Spacing Source Code Formatting Query Formatting Object Footers
The Standards What about SQL Server development standards? I think they should exist as well. A few jobs ago, I ran into issues with two other developers in examining each other's server code. We found that we were not only using different standards for layout, But Also for Accessing Objects in Transactions.
Over the last few years, I have continually developed and evolved my set of coding standards. Today, they exist as a document with my current company, but I still examine them at times to see if they are truly worthy of being "standards". After All, I Implement The Best Solution for Each Category.
The Really Standards and Naming Standards. This Article Will Deal with The Naming Standards and Part 2 Will Discuss Coding Standards. Here is a current list of my standards:
Databases
Each database on a server should be named using a name that is logical and applicable to the use of the database. Since third party databases often require specific names, this specification can not give more concrete examples of naming standards. If you are building software which may Be Deployed ON Another Server, You May Wish To Prefix The Database Name with Some Acronym Signify Your Company, AS in Example 3.examples:
Sales Dynamics IBM_SALESANALYSIS
Backup Devices (Full Backup)
Any File That Contains a Complete Backup Should Be name> _ <4 Database Name> _ <4 Digit Year>
EXAMPLES:
Sales_20011015080000.bak Dynamics_20010908000000.bak
Backup Devices (DiffERENTIAL Backup)
Any file that contains a differential backup should be named in the following format:
EXAMPLES:
Sales_20011015083000.dif Dynamics_20010908120000.DIF
BACKUP DEVICES (Transaction Log Backup)
Any File That Contains a Transaction Log Backup SHOULD BE Named in The Following Format:
Sales_20011015081500.trn Dynamics_20010908080000.Trnlogins
All Login Names Should Follow The Company Standards for Network Login Names. Currently The Standard IS:
EXAMPLES:
Sjones bknight
Users
All Database User Names Should Match The login name to which it is mapped. No user accounts shouth. Use roles instead.
EXAMPLES:
Sjones bknight
Roles
All Database Roles Should Be named for the function of the role. This may be the name of the department or the job function.
EXAMPLES:
Marketing purchaasingagents
Tables
All Tables Should Be named for the function of the table. For multiple Word tables, The name Should be in proplex......
EXAMPLES:
Orders OrderLineItems
Columns
COLUMNS SHOULD FOLLOW The Same Naming Convention As for Tables. Proper case..
EXAMPLES:
ORDERID ProductCode QuantityPurchased
Views
All view names should begin with a lower case "v" and then follow the same naming conventions as for a table. Proper case all words in the name with no internal spaces. If this is a view of a single table and contains all fields, THEN USE "V" Plus the Table Name.examples:
Vorderdetails vproduct
Indexes
All indexes should be named in the following format: