Skip to content

SA0067A : Check all Unique Key Constraints in the current database for following specified naming convention

Inconsistent or unclear unique constraint naming can impact database understanding and maintainability.

In database systems, maintaining consistent naming conventions for unique constraints is crucial for clarity and maintainability. This consistency helps database administrators and developers quickly understand the functional intent and relationship of constraints within the database schema.

For example:

-- Example of a poorly named unique constraint
ALTER TABLE Employees ADD CONSTRAINT UK_Table_Col_1 UNIQUE (EmpID, EmpEmail);

This example lacks a clear naming convention. It doesn’t provide clear information about the table and columns involved, which can lead to confusion and maintenance challenges.

  • Increase in chances of naming conflicts, especially in larger databases.

  • Difficulty in understanding the purpose and application of constraints, affecting documentation, learning, and onboarding processes.

Ensure that unique constraints follow a consistent naming convention for clarity and ease of maintenance.

Follow these steps to address the issue:

1.Identify the existing unique constraint that lacks a proper naming convention. Use sp_helpconstraint to list constraints on a table.

2.Review and decide on a meaningful naming pattern that includes the table name and columns involved. For example, UC_TableName_ColumnName1_ColumnName2 .

3.Alter the table to rename the constraint using sp_rename . Ensure the new name adheres to your established convention.

For example:

-- Step 1: Check existing constraints
EXEC sp_helpconstraint 'Employees';
-- Step 3: Rename the constraint
EXEC sp_rename 'UK_Table_Col_1', 'UC_Employees_EmpID_EmpEmail', 'OBJECT';

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

Name Description Default Value
NamePattern Unique key name pattern. UK*{table_name}*{column_list}
ColumnsListSeparator Separator which to be used for separating the columns in the {column_list} placeholder. _

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