SQL Server Naming Conventions and Standards
Estimated study time: 12 minutes. Consistent naming saves hours of confusion later.
SQL Server doesn't enforce a specific naming style, which means without a shared convention, a schema can quickly become inconsistent as more people contribute to it. Picking a standard early — and sticking to it — keeps a database easy to navigate.
Tables
- Use plural, descriptive nouns:
Customers,Orders,Invoices - Avoid prefixes like
tbl_— the object type is already clear from context - Use PascalCase or snake_case consistently, never both in the same database
Columns
- Name columns clearly:
FirstNamerather thanfn - Primary keys are often named
IdorTableNameId(e.g.,CustomerId) - Boolean-style columns should read like a question:
IsActive,HasDiscount
Keys and Constraints
PK_Customers -- Primary key FK_Orders_Customers -- Foreign key from Orders to Customers UQ_Customers_Email -- Unique constraint CK_Products_Price -- Check constraint
Stored Procedures and Views
usp_GetCustomerOrders -- 'usp' = user stored procedure vw_ActiveCustomers -- views prefixed with 'vw'
User, Order, or Group) as table or column names — they force you to use brackets everywhere, which clutters every query.Why Standards Matter
A consistent naming convention makes it far easier for new developers to guess column and table names correctly, reduces bugs from case-sensitivity mismatches, and keeps auto-generated documentation readable.
Naming the Objects Not Covered Above
Tables, columns, keys, procedures and views are only part of a schema. Indexes, triggers, functions and schemas deserve the same consistency.
| Object | Pattern | Example |
|---|---|---|
| Non-clustered index | IX_Table_Column(s) | IX_Orders_CustomerId |
| Unique index | UX_Table_Column(s) | UX_Users_Email |
| Default constraint | DF_Table_Column | DF_Orders_CreatedAt |
| Trigger | TR_Table_Action | TR_Orders_AfterInsert |
| Scalar or table function | ufn_Verb or fn_Verb | ufn_GetOrderTotal |
| Schema | Short business area | sales, hr, audit |
Schemas are an underused tool. Grouping tables as sales.Orders and hr.Employees often removes the temptation to cram the area into every table name, and it lets you grant permissions per schema.
Worked Example: A Table Created to Standard
When you do not name constraints yourself, SQL Server generates names with random suffixes, such as PK__Orders__C3905BAF. These differ between environments and make deployment scripts painful. Name them explicitly:
CREATE TABLE sales.Orders
(
OrderId INT IDENTITY(1,1) NOT NULL,
CustomerId INT NOT NULL,
OrderDate DATETIME2(0) NOT NULL,
TotalAmount DECIMAL(12,2) NOT NULL,
IsCancelled BIT NOT NULL,
CONSTRAINT PK_Orders PRIMARY KEY (OrderId),
CONSTRAINT FK_Orders_Customers FOREIGN KEY (CustomerId)
REFERENCES sales.Customers (CustomerId),
CONSTRAINT CK_Orders_TotalAmount CHECK (TotalAmount >= 0),
CONSTRAINT DF_Orders_IsCancelled DEFAULT (0) FOR IsCancelled
);
CREATE INDEX IX_Orders_CustomerId_OrderDate
ON sales.Orders (CustomerId, OrderDate);
Anyone reading an error message such as "conflicted with the CHECK constraint CK_Orders_TotalAmount" now knows the table and column immediately.
Rules That Prevent Real Problems
- Never start procedure names with
sp_. SQL Server reserves that prefix for system procedures and checks the master database first, which adds overhead and risks a name clash. That is why the convention above usesusp_. - Avoid spaces and special characters. A name like
[Order Details]forces brackets in every query and breaks some tools. - Do not rely on case. Depending on the collation,
CustomerIDandCustomerIdmay or may not be treated as the same name. Pick one spelling and keep it everywhere. - Keep foreign key columns identical to the referenced key.
Orders.CustomerIdpointing atCustomers.CustomerIdmakes joins self-explanatory. - Avoid unclear abbreviations.
Qtyis widely understood;CstAdrLn2is not. - Name dates by meaning.
CreatedAt,ShippedOnandExpiresAtsay more thanDate1.
Rolling Out a Convention on an Existing Database
Renaming objects in a live system is risky, because procedures, reports and application code may reference the old names. A safer approach is to apply the standard to all new objects immediately, then rename older ones gradually during planned changes, searching the codebase and sys.sql_modules for references before each rename.
Checklist for a new object: correct schema, descriptive name in the agreed casing, no reserved words, explicitly named constraints and indexes, and the convention documented where every contributor can find it.