Code Style Guidelines (Microsoft SQL Server (MS SQL))

Naming Conventions

1. Use PascalCase for table and column names.

2. Prefix stored procedures with usp_, views with vw_, and tables with tbl_.

3. Avoid using SQL keywords as names.

Indentation & Whitespace

1. Use a 2-space indent for nested statements.

2. Place each column name in a SELECT statement on a new line.

SQL Syntax

1. Write SQL keywords in uppercase.

2. Use semicolons to end SQL statements.

Joins

1. Always use explicit JOIN syntax rather than comma-separated syntax.

Aliasing

1. Use meaningful aliases for tables and columns where needed.

Comments

1. Use comments to explain complex queries or database operations.

String Concatenation

1. Use + for string concatenation.

Stored Procedures

1. Encapsulate complex operations in stored procedures.

Last updated