Explain Codes LogoExplain Codes Logo

Database Naming Conventions by Microsoft?

sql
naming-conventions
readability
best-practices
Nikita BarsukovbyNikita Barsukov·Aug 6, 2024
TLDR

Employ PascalCase for table and column names, keeping them singular and descriptive. Aim for no spaces and alphabetic characters. Here is a fast example:

-- Tables Employee // Who knew, an(!) employee. Product // Toys, games, candies?! -- Columns EmployeeID // Identity crisis solved! ProductPrice // Is it pricey or price-less?

Underline consistency and readability for smooth understanding and maintenance.

Quick Wins: Avoiding Common Mistakes

When defining stored procedures and functions, use the usp_ and ufn_ prefixes correspondingly. This is to prevent confusion with system stored procedures, which commonly use the sp_ prefix. Fun fact: using sp_ can cause SQL Server to do a detour and check the master database first, slowing down your coffee break.

Readability is a Virtue: Lowercase for Clarity

Give a hand to the readability of your code with lowercase in column names - it truly shines when combined with uppercase SQL keywords. Believe it or not, SELECT EmployeeID, EmployeeName FROM Employee WHERE EmployeeStatus = 'Active'; is easier to read and understand than a similar query in a chaotic casing mess. Think of your future self or a fellow developer.

Teamwork Makes the Dream Work: Consensus on Naming

In a team, agree on a common style for naming. Individual styles are like ice cream flavors - everyone has their favorite, but mixing too many can make a mess. Set a shared standard to ensure code maintainability.

Tapping into a Knowledge Goldmine: Existing Standards

Dive into the world of Joe Celko's SQL books and the ISO 11179 standard. These resources give you more than just naming conventions - prepare for deep dives into semantic clarity and data element definitions. For a living example of these standards, check the AdventureWorks Data Dictionary.

The Unsettling Table Naming Debate: Practicality Over Preference

Heated debates over table naming shouldn't overshadow the real goal: practicality. Keep your focus on the conventions that support efficient development and collaboration, not just preference.

Your Sidekick: Enhancing SQL Server Management Studio

Enhance the scripting features in SQL Server Management Studio. By configuring it to adhere to your naming conventions, you can increase code generation and readability.

Drawing Inspiration: AdventureWorks and Konstantin's Guidelines

Witness these principles in action with the AdventureWorks Data Dictionary. Bear in mind, though, that there is no 'one size fits all' solution. Deviations even within AdventureWorks from guidelines provided by external resources happen. Context, as they say, is king.

For a more structured approach, Konstantin's GitHub documentation on SQL naming conventions deploys robust industry standards.