Click or drag to resize

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.

Therefore, 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

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Categories

Design Rules, New Rules

Additional Information

There is no additional info for this rule.

Example Test Script
 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;

Analysis Results

 MessageLineColumn
1SA0188 : The NULL or NOT NULL constraint not explicitly specified in the table column definition.30
2SA0188 : The NULL or NOT NULL constraint not explicitly specified in the table column definition.730
3SA0188 : The NULL or NOT NULL constraint not explicitly specified in the table column definition.928
See Also

Other Resources