SA0075B : Avoid adding constraints with default system generated name |
![]() |
The topic describes the SA0075B analysis rule.

Avoid adding constraints with default system generated name

The rule checks CREATE TABLE and ALTER TABLE statements for constraints created without specifying constraint name.
Such constraints will be are created with system generated name.

Review the CREATE/ALTER TABLE statement and explicitly provide name for the constraint.

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

Name | Description | Default Value |
---|---|---|
IgnoreTemporaryTables |
Ignore temporary tables. |
yes |

The rule does not need Analysis Context or SQL Connection.


Naming Rules, Bugs

There is no additional info for this rule.

SQL
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); |

Message | Line | Column | |
---|---|---|---|
1 | SA0075B : The constraint will be added with default system generated name. | 3 | 35 |
2 | SA0075B : The constraint will be added with default system generated name. | 6 | 17 |
3 | SA0075B : The constraint will be added with default system generated name. | 8 | 4 |
4 | SA0075B : The constraint will be added with default system generated name. | 13 | 0 |
5 | SA0075B : The constraint will be added with default system generated name. | 17 | 0 |
6 | SA0075B : The constraint will be added with default system generated name. | 26 | 35 |
7 | SA0075B : The constraint will be added with default system generated name. | 27 | 27 |
8 | SA0075B : The constraint will be added with default system generated name. | 29 | 4 |
9 | SA0075B : The constraint will be added with default system generated name. | 33 | 24 |
10 | SA0075B : The constraint will be added with default system generated name. | 35 | 24 |
… |
