SA0080 : Do not use VARCHAR or NVARCHAR data types without specifying length

The topic describes the SA0080 analysis rule.

Message

Do not use VARCHAR or NVARCHAR data types without specifying length

Description

The rule checks the T-SQL code for use VARCHAR or NVARCHAR data types without specifying length.

Do not define columns, variables and parameters using VARCHAR, and NVARCHAR data types without specifying length attribute. This will not produce a dynamic length string data, but will make SQL Server choose default length of 1 (NOTE: In some scenarios it the length can be 30).

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

Additional Information

There is no additional info for this rule.

Example Test Script
SQL
 1DECLARE @var nvarchar(20)
 2DECLARE @var1 nchar(11)
 3DECLARE @var2 varchar 
 4DECLARE @var3 nvarchar
 5
 6DECLARE @var4 [VARCHAR]
 7DECLARE @var5 [NVARCHAR]
 8
 9DECLARE @var41 [VARCHAR](30)
10DECLARE @var51 [NVARCHAR](30)
11
12DECLARE @var6 [VARCHAR]
13DECLARE @var7 [NVARCHAR] -- IGNORE:SA0080

Analysis Results

  Message Line Column
1 SA0080 : Do not use VARCHAR or NVARCHAR data types without specifying length. 3 14
2 SA0080 : Do not use VARCHAR or NVARCHAR data types without specifying length. 4 14
3 SA0080 : Do not use VARCHAR or NVARCHAR data types without specifying length. 6 14
4 SA0080 : Do not use VARCHAR or NVARCHAR data types without specifying length. 7 14
5 SA0080 : Do not use VARCHAR or NVARCHAR data types without specifying length. 12 14
See Also

Other Resources