DF038: The constraint name is not explicitly specified.
Last modified: December 25, 2024
The topic describes the DF038 T-SQL code analysis rule.
Category
NAMING CONVENTIONS
Message
The constraint name is not explicitly specified.
Description
To facilitate database maintenance, it is recommended to explicitly name constraints so that they can be easily referenced when needed.
Additional information
When the constraint name is not explicitly specified in SQL, the DBMS automatically generates a default name for the constraint, typically combining the table name with a system-generated identifier. This can lead to less readable and harder-to-manage schema definitions, making tasks like error resolution and constraint modification more challenging due to the non-descriptive and unpredictable default names.
Noncompliant code example
CREATE TABLE dbo.Customers(
CustomerId INT PRIMARY KEY CLUSTERED,
CustomerName VARCHAR(255) NOT NULL
);
Compliant solution
CREATE TABLE dbo.Customers(
CustomerId INT CONSTRAINT PK_Customers PRIMARY KEY CLUSTERED,
CustomerName VARCHAR(255) NOT NULL
);
Was this page helpful?