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 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
3.8 ★ | 5 Vote
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
- Word 2013 full-text tutorial (Part 12): How to break pages, paragraph breaks
- How to crack Windows 10 password, how to break password on Windows 10
- No need to be a singer, you can still smash a glass of water with singing
May be interested
- CONTINUE command in SQL Serverthe continue command is used to give command execution authority to the last expression of the loop. that means upside-down to the top of the loop, all the commands that follow in the loop containing continue will be ignored without execution.
- GOTO command in SQL Serverthe goto command is a simple jump command, which allows an unconditional jump program from goto to a location in the program that has a label (laber) command in the same function.
- Instructions for installing SQL Server 2019on september 24, microsoft announced the release of sql server 2019 community technical preview (ctp) 2.0. it is very suitable for database professionals to keep up with modern technology.
- WHILE loop in SQL Serverthe while loop is used if you want to run a code repeatedly when the given condition returns true. let's find out how to use while in sql server with network administrator.
- FOR loop in SQL Serverthe for loop is often used to run a code repeatedly for the number of repetitions. however, in sql server there is no for loop.
- ASCII function in SQL Serverthe article will explore and guide you how to use the ascii () function in sql server.