GOTO statement in SQL SERVER

Written on May 06, 2016

GOTO statement is used to break execution of flow and move execution directly to label specified. Its syntax is as below.

Here, label names must be unique.


Think twice before using GOTO in your code!

Most programmers avoid using GOTO. The main reason behind is, it'll make code look like spaghetti. It'll make difficult to understand flow of control of your program. GOTO statement can easily replace using control-flow statements like IF-ELSE or WHILE.

There is famous article by Edsger W. Dijkstra on harmfulness of GOTO, take a look.