SA0188 : The NULL or NOT NULL constraint not explicitly specified in the table column definition

The topic describes the SA0188 analysis rule.

Message

The NULL or NOT NULL constraint not explicitly specified in the table column definition

Description

The checks CREATE TABLE and ALTER TABLE ADD COLUMN statements for table column definitions not having explicit NULL constraint specified.

If the NOT NULL option is not explicitly specified when creating a table, the NULL value will be applied to all columns.

How to fix

It is recommended to always set the availability of empty values in a column when creating a table, or declaring a temporary table, or a table variable.

Scope

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

Parameters
Name Description Default Value
CheckTableVariables

The parameter specifies whether to check table variable definitions and report missing NULL constraints.

yes

Remarks

The rule does not need Analysis Context or SQL Connection.

Effort To Fix
5 minutes per issue.
Categories

Design Rules, Code Smells

Additional Information

There is no additional info for this rule.

Example Test SQL
SQL
 1CREATE TABLE Test.Greeting
 2(
 3GreetingId INT IDENTITY (1,1) PRIMARY KEY,
 4Message nvarchar(255) NOT NULL,
 5)
 6
 7ALTER TABLE Test.Greeting ADD Column2 INT, Column2 INT NULL
 8
 9ALTER TABLE dbo.doc_exa ADD column_b VARCHAR(20), column_c INT NULL ;  
10
11ALTER TABLE MyTable ALTER COLUMN NullCOl NVARCHAR(20) NOT NULL; 
12
13DECLARE @greetingsTable AS TABLE 
14(
15        GreetingId INT IDENTITY (1,1) PRIMARY KEY,
16        Message nvarchar(255) NOT NULL,
17)

Analysis Results
  Message Line Column
1 SA0188 : The NULL or NOT NULL constraint not explicitly specified in the table column definition. 3 0
2 SA0188 : The NULL or NOT NULL constraint not explicitly specified in the table column definition. 7 30
3 SA0188 : The NULL or NOT NULL constraint not explicitly specified in the table column definition. 9 28
4 SA0188 : The NULL or NOT NULL constraint not explicitly specified in the table column definition. 15 1
See Also

Other Resources