Click or drag to resize

SA0268 : Table variable is not used as table source

The topic describes the SA0268 analysis rule.

Message

Table variable is not used as table source

Description

The rule checks T-SQL code for table variables declared, but not used as a table source in any FROM clause of following SELECT, UPDATE, DELETE or MERGE statements.

Review the code and the table variable usages and remove it if is not really needed.

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
SQL
 1DECLARE @Greeting TABLE
 2(
 3GreetingId INT IDENTITY (1,1) PRIMARY KEY,
 4Message nvarchar(255) NOT NULL
 5);
 6
 7SELECT * INTO #Greeting2 FROM dbo.Greeting
 8
 9INSERT INTO @Greeting (Message) 
10SELECT 'Hello!'
11UNION ALL 
12SELECT 'Hi!'
13UNION ALL
14SELECT 'Hello, world!'
15
16DELETE  @Greeting WHERE GreetingId = 3
17
18-- SELECT * FROM @Greeting g WHERE g.Message like 'Hello%'

Analysis Results

 MessageLineColumn
1SA0268 : Table variable is not used as table source.18
See Also

Other Resources