SQL Style Guide

General

This style guide is based on writing database for Azure SQL Database. If you're using a different RDMS there may be subtle differences.

All object names should use the Pascal Case conventions.

Tables

Table names should be singular nouns.

Column names should describe an attribute of the table. For example FirstName, LastName columns describe attributes of a Person table.

Recommended columns for data management:

  • IsActive: Used as part of a "soft delete" strategy
  • ModifiedBy: Used for auditing
  • ModifiedDate : Used for auditing

For strict auditing requirements that call for the "as of" state of a table row use a temporal table.

Columns

Column names should describe an attribute of the table.

Columns that are foreign keys should be named a concatenation of the referencing table and its primary key. For example the foreign key column to an OrderDetail table referencing the Order table should be named OrderId.

Primary Keys

Surrogate keys should be named Id.

Natural keys should not use Id in the name.

Surrogate keys should use a sequence for system generated values.

Views

Views and table valued functions should named be plural nouns.

Stored Procedures

Stored procedure names should be a verb noun combination. For example GetCustomerOrder or InsertCustomerOrder.

User Defined Functions

Scalar functions should named be a verb singular noun combination. For example FormatOrderDate.

Like views, table valued functions should have a plural noun name.