Minor
Column references should not have more than two-parts
Description
The "Column references should not have more than two-parts" rule states that when referencing columns in a SQL Server query, the column name should not contain more than two parts. This means that a column name should not contain any dot notation or any other type of delimiter which would create multiple parts. For example, a column name such as "dbo.users.name" would not be allowed, while "users.name" would be allowed.
This rule is in place to ensure that queries are as simple and efficient as possible. Having multiple parts in a column reference can lead to confusion and can make it difficult to read and understand the query. It can also lead to errors if the wrong column is referenced.
Key Benefits
- Eliminates potential for mistakes - By limiting the number of parts in a column reference, potential for mistakes is eliminated.
- Improves readability - By reducing the complexity of column references, they become easier to read and understand.
- Makes maintenance easier - With fewer parts in a column reference, it is easier to maintain and troubleshoot.
Non-compliant Code Example
SELECT Production.Product.ProductID, --Non compliant code (Column reference has more than two parts) Production.Product.Name, --Non compliant code (Column reference has more than two parts) Product.Color FROM Production.Product ORDER BY ListPrice;
Compliant Code Example
SELECT Product.ProductID, --Compliant code (Column reference has two or less parts)
Product.Name,
Color
FROM Production.Product
ORDER BY ListPrice;