goto label

Description

Branches to a user-defined label.

Syntax

label: 
	goto label

Examples

Example 1

Shows the use of a label called restart:

declare @count smallint 
select @count = 1 
restart: 
  print "yes" 
select @count = @count + 1 
while @count <=4 
  goto restart

Usage

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

goto permission defaults to all users. No permission is required to use it.

See also

Commands if...else, while