SA0273 : The USE statement must be the first statement in the script

The topic describes the SA0273 analysis rule.

Message

The USE statement must be the first statement in the script

Description

The rule checks SQL code and reports when a USE statement is not the first statement in the script file.

How to fix

Move the USE statement at the top of the SQL document.

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
2 minutes per issue.
Categories

Design Rules, New Rules

Additional Information

There is no additional info for this rule.

Example Test SQL
SQL
 1CREATE TABLE Test.Greeting
 2(
 3GreetingId INT IDENTITY (1,1) PRIMARY KEY,
 4Message nvarchar(255) NOT NULL,
 5)
 6
 7
 8USE DB1
 9
10
11INSERT INTO Test.Greeting (Message) 
12SELECT 'Hello!'
13UNION ALL 
14SELECT 'Hi!'
15UNION ALL
16SELECT 'Hello, world!'
17
18INSERT INTO Test.Greeting (Message) 
19VALUES ('How do yo do?'),
20        ('Good morning!'),
21        ('Good night!')
22
23DELETE  Test.Greeting WHERE GreetingId = 3
24
25SELECT * FROM Test.Greeting g 
26WHERE 
27g.Message like 'Hello%'
28
29DROP TABLE Test.Greeting

Analysis Results
  Message Line Column
1 SA0273 : The USE statement must be the first statement in the script. 10 0
See Also

Other Resources