SA0191 : Procedure body is not enclosed in BEGIN…END block

The topic describes the SA0191 analysis rule.

Message

Procedure body is not enclosed in BEGIN…END block

Description

The rule checks for CREAT/ALTER PROCEDURE statements and reports if the procedure body is not enclosed in a BEGIN..END block.

How to fix

Enclose the procedure body explicitly in a `BEGIN..END` block.

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, Code Smells

Additional Information

There is no additional info for this rule.

Example Test SQL
SQL
1CREATE PROCEDURE HumanResources.uspGetAllEmployees
2AS 
3SET  NOCOUNT ON;
4
5SELECT  LastName, FirstName, JobTitle, Department
6FROM  HumanResources.vEmployeeDepartment;

Example Test SQL with Automatic Fix
SQL
 1CREATE PROCEDURE HumanResources.uspGetAllEmployees
 2AS 
 3BEGIN
 4
 5SET  NOCOUNT ON;
 6
 7SELECT  LastName, FirstName, JobTitle, Department
 8FROM  HumanResources.vEmployeeDepartment;
 9
10END

Analysis Results
  Message Line Column
1 SA0191 : Procedure body is not enclosed in BEGIN…END block. 1 0
See Also

Other Resources