Click or drag to resize

SA0067B : Check all Unique Key Constraints in the current database for following specified naming convention.(Batch)

The topic describes the SA0067B analysis rule.

Message

Check all Unique Key Constraints in the current database for following specified naming convention.(Batch)

Description

The rule checks the naming of all unique constraints in the SQL code.

The NamePattern variable can be used to select or configure the desired pattern which will be used to check the object name.

The following placeholders will be replaced in the pattern during the key testing:

{table_name} - Name of the key's parent table.

{column_list} - List of the key columns, ordered by key ordinal and separated by underscore('_').

Regular expression patterns can be used, but the pattern must be prefixed with 'regexp:' string in order to be used as a matching regular expression.

Scope

The rule has a Batch scope and is applied only on the SQL script.

Parameters
NameDescriptionDefault Value
NamePattern

Dfault unique key name pattern.

UK_{table_name}_{column_list}

ColumnsListSeparator

Separator which to be used for separating the columns in the {column_list} placeholder.

_

UniqueClusteredNamePattern

Name pattern for unique clustered constraints.

AK_{table_name}_{column_list}

UniqueNonClusteredNamePattern

Name pattern for unique non-clustered constraints.

-

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Naming Rules, New Rules

Additional Information

There is no additional info for this rule.

Example Test Script
 1CREATE TABLE Persons (
 2    ID int NOT NULL,
 3    LastName varchar(255) NOT NULL,
 4    FirstName varchar(255),
 5    Age int,
 6    CONSTRAINT UC_Person UNIQUE (ID,LastName)
 7); 
 8
 9ALTER TABLE Persons
10ADD CONSTRAINT UC_Person UNIQUE CLUSTERED (ID,LastName); 
11
12ALTER TABLE Persons 
13ADD UNIQUE (ID); 
14
15CREATE TABLE Persons (
16    ID int NOT NULL UNIQUE,
17    LastName varchar(255) NOT NULL,
18    FirstName varchar(255),
19    Age int,
20    UniqueId int not null CONSTRAINT AK_Person_UniqueId UNIQUE CLUSTERED
21);

Analysis Results

 MessageLineColumn
1SA0067B : The unique key constraing name UC_Person does not match the naming convention. The expected name is [UK_Persons_IDLastName].715
2SA0067B : The unique key constraing name UC_Person does not match the naming convention. The expected name is [AK_Persons_IDLastName].1115
3SA0067B : The unique key constraing name AK_Person_UniqueId does not match the naming convention. The expected name is [AK_Persons_UniqueId].2137
See Also

Other Resources