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: FirstName rather than fn
  • Primary keys are often named Id or TableNameId (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'
💡 Tip: Avoid using SQL Server reserved words (like 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.

ObjectPatternExample
Non-clustered indexIX_Table_Column(s)IX_Orders_CustomerId
Unique indexUX_Table_Column(s)UX_Users_Email
Default constraintDF_Table_ColumnDF_Orders_CreatedAt
TriggerTR_Table_ActionTR_Orders_AfterInsert
Scalar or table functionufn_Verb or fn_Verbufn_GetOrderTotal
SchemaShort business areasales, 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 uses usp_.
  • 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, CustomerID and CustomerId may 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.CustomerId pointing at Customers.CustomerId makes joins self-explanatory.
  • Avoid unclear abbreviations. Qty is widely understood; CstAdrLn2 is not.
  • Name dates by meaning. CreatedAt, ShippedOn and ExpiresAt say more than Date1.

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.

Ready to go beyond the basics?

Get hands-on training, live mentorship, and placement support with Uncodemy's Data Analytics Course.

Explore Data Analytics Course →