BREAK (Control Interrupt) command in SQL Server
The Break command used to exit the loop does not specify a stop condition or you want to stop the loop on condition that you specify and execute the statements following the loop statement END.
The Break command used to exit the loop does not specify a stop condition or you want to stop the loop on condition that you specify and execute the statements following the END command of the loop.
Syntax
To use the command to interrupt BREAK control in SQL Server, we use the following syntax:
BREAK;
There are no parameters and arguments in the BREAK statement.
Note:
- You use BREAK to end the WHILE loop early.
- If in the code there is WHILE nested LOOP, BREAK will terminate the nearest WHILE loop.
For example
DECLARE @Number INT = 1;
DECLARE @Total INT = 0;
@Number WHILE <= 10
BEGIN
IF @NUMBER = 5
BREAK;
ELSE
SET @Total = @Total + @Number;
SET @Number = @Number + 1;
END
PRINT @Total;
GO
In this example using the BREAK statement, the WHILE loop will end when @Number reaches value 5.
Previous article: FOR loop in SQL Server
Next lesson: CONTINUE command in SQL Server
Discover more
break command mssqlShare by
Jessica Tanner
Update 25 May 2019
You should read it
- What happens when we break our fingers 'cracked'?
- How to Break a Chain
- Page break in Word - Instructions on how to break a page in Word 2007, 2010, 2013, 2016
- Out of love but afraid to express? Don't worry, there's Breakup Shop
- How to break Excel Password without software
- The Quiet Details That Make a Sports Betting Platform Feel Reliable
- Instructions on creating toy set images with ChatGPT AI
- How are AI agents changing the journalism industry?
- CONTINUE command in SQL Server
- GOTO command in SQL Server
- Instructions for installing SQL Server 2019