DF186: GOTO statement is used.
Last modified: May 28, 2025
The topic describes the DF186 T-SQL code analysis rule.
Category
BEST PRACTICE
Message
GOTO statement is used.
Description
To improve readability, it is recommended to avoid using the GOTO statement.
Noncompliant code example
DECLARE @Counter int;
SET @Counter = 1;
WHILE @Counter < 10
BEGIN
SELECT @Counter AS counter
SET @Counter = @Counter + 1
IF @Counter = 4
BEGIN
GOTO Branch_One --Jumps to the first branch.
END
IF @Counter = 5
BEGIN
GOTO Branch_Two --This will never execute.
END
END
Branch_One:
SELECT 'Jumping To Branch One.' AS message
GOTO Branch_Three; --This will prevent Branch_Two from executing.
Branch_Two:
SELECT 'Jumping To Branch Two.' AS message
Branch_Three:
SELECT 'Jumping To Branch Three.' AS message
Was this page helpful?
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.