SA0043B : Avoid using reserved words for type names

The topic describes the SA0043B analysis rule.

Message

Avoid using reserved words for type names

Description

The rule checks the T-SQL code for creation of user defined types using a reserved word as a type name.

You should avoid using a reserved word as the name of a user-defined type because readers will have a harder time understanding your database code. You can use reserved words in SQL Server as identifiers and object names only if you use delimited identifiers.

How to fix

Review the reported types, which use reserved keywords for the type name, and consider different name for the type.

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.

Effort To Fix
5 minutes per issue.
Categories

Naming Rules, Code Smells

Additional Information

There is no additional info for this rule.

Example Test SQL
SQL
 1--  keyword as a type name misuse
 2CREATE TYPE dbo.[Alter] FROM varchar(11) NOT NULL ; --  'Alter' is a reserved keyword
 3CREATE TYPE [Order] FROM varchar(11) NOT NULL ; --  'Order' is a reserved keyword
 4
 5
 6
 7EXEC sp_addtype N'Alter', N'char(10)',N'not null' --  'Alter' is a reserved keyword
 8EXEC sp_addtype N'Table', N'char(10)',N'not null' --  'Table' is a reserved keyword
 9EXEC sp_addtype N'Order', N'char(10)',N'not null' --  'Order' is a reserved keyword
10
11
12EXEC sp_addtype N'', N'char(10)',N'not null' --  'Order' is a reserved keyword
13
14
15EXEC sys.sp_addtype [Alter], N'char(10)',N'not null' --  Alter is a reserved keyword
16EXEC sp_addtype dbo.[Alter], N'char(10)',N'not null' --  Alter is a reserved keyword
17
18
19EXEC sp_addtype N'AlterType', N'char(10)',N'not null'
20
21EXEC sp_addtype N'TableType', N'char(10)',N'not null'

Analysis Results
  Message Line Column
1 SA0043B : Avoid using reserved words for type names. 3 16
2 SA0043B : Avoid using reserved words for type names. 4 12
3 SA0043B : Avoid using reserved words for type names. 8 16
4 SA0043B : Avoid using reserved words for type names. 9 16
5 SA0043B : Avoid using reserved words for type names. 10 16
6 SA0043B : Avoid using reserved words for type names. 16 20
7 SA0043B : Avoid using reserved words for type names. 17 20
See Also

Other Resources