The goto keyword causes unconditional branching to a user-defined label. goto and labels can be used in stored procedures and batches.

A label’s name must follow the rules for identifiers and must be followed by a colon when it is first given. It is not followed by a colon when it is used with goto.

The syntax for goto is:

     goto label 

This example uses goto and a label, a while loop, and a local variable as a counter:

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

goto is usually dependent on a while or if test or some other condition, to avoid an endless loop between goto and the label.