Click or drag to resize

SA0069B : Check all Default Constraints in the current script for following specified naming convention.(Batch)

The topic describes the SA0069B analysis rule.

Message

Check all Default Constraints in the current script for following specified naming convention.(Batch)

Description

The rule checks the naming of all default constraints used in CREATE TABLE and ALTER TABLE statements in the current sql script.

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_name} - Target column name.

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

Deault constraint name pattern.

DF_{table_name}_{column_name}

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 Orders (
 2    ID int NOT NULL,
 3    OrderNumber int NOT NULL,
 4    OrderDate date CONSTRAINT DF_DefaultDate DEFAULT GETDATE()
 5);
 6
 7CREATE TABLE Orders (
 8    ID int NOT NULL,
 9    OrderNumber int NOT NULL CONSTRAINT DF_DefaultNumber DEFAULT 1,
10    OrderDate date CONSTRAINT DF_DefaultDate DEFAULT GETDATE()
11);
12
13ALTER TABLE Persons 
14ADD OrderDate date NOT NULL CONSTRAINT DF_DefaultDate DEFAULT GETDATE();
15
16ALTER TABLE Persons 
17ADD OrderDate date NOT NULL CONSTRAINT DF_DefaultDate DEFAULT GETDATE(),
18 OrderNumber INT CONSTRAINT DF_DefaultDate DEFAULT 1;
19
20ALTER TABLE Orders 
21ADD CONSTRAINT DF_DefaultDate DEFAULT GETDATE() FOR OrderDate,
22CONSTRAINT DF_DefaultDate DEFAULT 1 FOR OrderNumber;
23
24CREATE TABLE Persons (
25    ID int NOT NULL,
26    LastName varchar(255) NOT NULL,
27    FirstName varchar(255),
28    Age int,
29    City varchar(255) DEFAULT 'Sandnes'
30);
31
32CREATE TABLE Orders (
33    ID int NOT NULL,
34    OrderNumber int NOT NULL,
35    OrderDate date DEFAULT GETDATE()
36);
37
38ALTER TABLE Persons 
39ADD OrderDate date NOT NULL DEFAULT GETDATE();

Analysis Results

 MessageLineColumn
1SA0069B : The default constraint name DF_DefaultDate does not match the naming convention. The expected default constraint name is [DF_Orders_OrderDate].430
2SA0069B : The default constraint name DF_DefaultNumber does not match the naming convention. The expected default constraint name is [DF_Orders_OrderNumber].940
3SA0069B : The default constraint name DF_DefaultDate does not match the naming convention. The expected default constraint name is [DF_Orders_OrderDate].1030
4SA0069B : The default constraint name DF_DefaultDate does not match the naming convention. The expected default constraint name is [DF_Persons_OrderDate].1439
5SA0069B : The default constraint name DF_DefaultDate does not match the naming convention. The expected default constraint name is [DF_Persons_OrderDate].1739
6SA0069B : The default constraint name DF_DefaultDate does not match the naming convention. The expected default constraint name is [DF_Persons_OrderNumber].1828
7SA0069B : The default constraint name DF_DefaultDate does not match the naming convention. The expected default constraint name is [DF_Orders_OrderDate].2115
8SA0069B : The default constraint name DF_DefaultDate does not match the naming convention. The expected default constraint name is [DF_Orders_OrderNumber].2211
See Also

Other Resources