WHILE (and CONTINUE)
loop while TRUE; BREAK exits, CONTINUE restarts
What changes
- Input
- boolean condition
- Output or change
- none
Syntax at a glance
WHILE boolean_expression { sql_statement | statement_block | BREAK | CONTINUE }
Work example
A controlled task needs the behavior documented for WHILE (and CONTINUE) before it is added to a batch.
Read the linked Microsoft syntax and test WHILE (and CONTINUE) with synthetic input in an isolated database. Record its scope, permissions, and error path.
Check your work WHILE (and CONTINUE). The observed WHILE (and CONTINUE) behavior matches its written purpose and the test has no effect on permanent data or credentials.
Practice SQL
Open in SQL FlowDECLARE @Step int = 1;
WHILE @Step <= 3
BEGIN
SELECT @Step AS StepNumber;
SET @Step += 1;
END;
Open Microsoft Learn for full syntax, permissions, and details for your version.