Click or drag to resize

SA0075B : Avoid adding constraints with default system generated name

The topic describes the SA0075B analysis rule.

Message

Avoid adding constraints with default system generated name

Description

The rule checks CREATE TABLE and ALTER TABLE statements in the for constraints created without specifying constraint name.

Such constraints will be are created with system generated name.

Scope

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

Parameters

Rule has no parameters.

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 REFERENCES Persons(LastName),
 4    FirstName varchar(255),
 5    Age int,
 6    UniqueId int UNIQUE CLUSTERED,
 7    CONSTRAINT PK_Person PRIMARY KEY (ID),
 8    FOREIGN KEY (FirstName,LastName) REFERENCES Persons(FirstName,LastName)
 9);
10
11ALTER TABLE Persons ADD 
12CONSTRAINT PK_Person PRIMARY KEY (ID,LastName),
13FOREIGN KEY (FirstName,LastName) REFERENCES Persons(FirstName,LastName);
14
15ALTER TABLE Persons ADD 
16CONSTRAINT PK_Person PRIMARY KEY (ID,LastName),
17FOREIGN KEY (FirstName,LastName) REFERENCES Persons(FirstName,LastName);
18
19CREATE TABLE Test.Greeting (
20    greetingId INT IDENTITY (1,1) PRIMARY KEY,
21    Message nvarchar(255) NOT NULL,
22);
23
24CREATE TABLE Persons (
25    ID int NOT NULL CONSTRAINT PK_Persons PRIMARY KEY CONSTRAINT DF_ID default(0),
26    LastName varchar(255) NOT NULL DEFAULT ('-'),
27    FirstName varchar(255) CHECK( FirstName like 'Bo%'),
28    Age int,
29    CHECK( Age > 20) 
30);
31
32
33ALTER TABLE Persons ADD PRIMARY KEY (ID);
34ALTER TABLE MyTable ADD CONSTRAINT DEF_Col1 DEFAULT 50 FOR Col1 ;  
35ALTER TABLE MyTable ADD DEFAULT '' FOR Col2 ;  
36ALTER TABLE MyTable ADD CHECK (Age > 20);

Analysis Results

 MessageLineColumn
1SA0075B : The constraint will be added with default system generated name.335
2SA0075B : The constraint will be added with default system generated name.617
3SA0075B : The constraint will be added with default system generated name.84
4SA0075B : The constraint will be added with default system generated name.130
5SA0075B : The constraint will be added with default system generated name.170
6SA0075B : The constraint will be added with default system generated name.2034
7SA0075B : The constraint will be added with default system generated name.2635
8SA0075B : The constraint will be added with default system generated name.2727
9SA0075B : The constraint will be added with default system generated name.294
10SA0075B : The constraint will be added with default system generated name.3324
...
See Also

Other Resources