Click or drag to resize

SA0042B : Avoid using special characters in object names. (Batch)

The topic describes the SA0042B analysis rule.

Message

Avoid using special characters in object names. (Batch)

Description

The rule checks the T-SQL code for creation of database objects with special characters in the name.

Naming a database object by using any special character (space, tab, newline, left square bracket, right square bracket, single quotation mark and double quotation mark) will make it more difficult not only to reference that object, but also to read code that contains the name of that object.

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

Naming Rules

Additional Information

There is no additional info for this rule.

Example Test Script
 1CREATE TABLE [dbo].[Table1]
 2( 
 3        [ID] INT NOT NULL IDENTITY(0, 1), 
 4        [Small'String] VARCHAR(10), -- contains special characters ( ' )
 5        [Small"String] VARCHAR(10), -- contains special characters ( " )
 6        [Small String] VARCHAR(10), -- contains special characters ( space )
 7        [Small        String] VARCHAR(10), -- contains special characters ( tab )
 8        [Small[String] VARCHAR(10), -- contains special characters ( square bracket )
 9    [Small]]String] VARCHAR(10) -- contains special characters ( square bracket )    
10)
11ON [PRIMARY]
12
13CREATE TABLE [dbo].[Table2]
14( 
15[ID] INT NOT NULL IDENTITY(0, 1), 
16[SmallString] VARCHAR(10)
17)
18ON [PRIMARY]

Analysis Results

 MessageLineColumn
1SA0042B : The name of the column [Small'String] contains quote character.41
2SA0042B : The name of the column [Small"String] contains quote character.51
3SA0042B : The name of the column [Small String] contains whitespace character.61
4SA0042B : The name of the column [Small String] contains whitespace character.71
5SA0042B : The name of the column [Small[String] contains square bracket character.81
6SA0042B : The name of the column [Small]]String] contains square bracket character.94
See Also

Other Resources