Skip to content

SA0072A : Check all Non-Key Indexes in the current database for following specified naming convention

Inconsistent or unclear index naming can lead to confusion and maintenance challenges.

Maintaining consistent naming conventions for indexes is crucial for efficient database management and clarity. Without a standardized naming approach, identifying and understanding the role and structure of indexes can become difficult, especially as database systems grow in complexity.

For example, consider an index with a non-descriptive or inconsistent name:

-- Example of poorly named index
CREATE INDEX IX_12345 ON TableName (ColumnName);

This index name does not provide information about its type, related table, or included columns, making it harder for database administrators and developers to manage and optimize.

  • Difficulty in understanding the index’s purpose and the columns it covers, leading to poor performance tuning and maintenance.

  • Increased risk of errors or redundant indexes due to unclear naming, complicating schema changes and data integrity.

  • Challenges in automating index management processes and generating documentation without clear naming conventions.

To resolve inconsistent index naming conventions in SQL Server, ensure all indexes follow a standardized naming approach that enhances clarity and aids in database management.

Follow these steps to address the issue:

1.Identify the indexes with non-descriptive or inconsistent names using a query like SELECT name FROM sys.indexes WHERE name NOT LIKE 'ExpectedPattern%'; to list indexes that deviate from your naming conventions.

2.Review the naming conventions to create a descriptive pattern. For example, use IX_TableName_ColumnNames to incorporate the table and columns involved, clarifying the index’s purpose.

3.Rename the index using the sp_rename stored procedure: EXEC sp_rename 'OldIndexName', 'NewIndexName'; ensuring the new name adheres to the established naming conventions.

4.Verify that the renaming has been successful and that the indexes follow the updated conventions using the query SELECT name FROM sys.indexes WHERE name LIKE 'ExpectedPattern%'; .

For example:

-- Example of renaming an index
EXEC sp_rename 'IX_12345', 'IX_TableName_ColumnName';

The rule has a ContextOnly scope and is applied only on current server and database schema.

Name Description Default Value
ClusteredIndexNamePattern Clustered non-unique index name patten. CIX*{table_name}*{column_list}
ClusteredUniqueIndexNamePattern Unique clustered index name patten. IX*{table_name}*{column_list}
ColumnsListSeparator Separator which to be used for separating the columns in the {column_list} placeholder. _
NonClusteredIndexNamePattern Non-clustered non-unique index name pattern. IX*{table_name}*{column_list}
NonClusteredUniqueIndexNamePattern Non-clustered unique index name pattern. AK*{table_name}*{column_list}
SpatialIndexNamePattern Spatial index name pattern. SIdx*{table_name}*{column_list}
XmlIndexPrimaryNamePattern Primary XML index name pattern. PXML*{table_name}*{column_list}
XmlIndexSecondaryTypePathNamePattern Secondary XML Path index pattern. XMLPATH*{table_name}*{column_list}
XmlIndexSecondaryTypePropertyNamePattern Secondary XML Property index pattern. XMLPROPERTY*{table_name}*{column_list}
XmlIndexSecondaryTypeValueNamePattern Secondary XML Value index pattern. XMLVALUE*{table_name}*{column_list}

The rule requires Analysis Context. If context is missing, the rule will be skipped during analysis.

8 minutes per issue.

Naming Rules, Code Smells

There is no additional info for this rule.

Analysis Rules