BREAK (Transact-SQL)

Applies to: yesSQL Server (all supported versions) YesAzure SQL Database YesAzure SQL Managed Instance yesAzure Synapse Analytics yesParallel Data Warehouse

BREAK exits the current WHILE loop. If the current WHILE loop is nested inside another, BREAK exits only the current loop, and control is given to the next statement in the outer loop.

BREAK is usually inside an IF statement.


WHILE (1=1)
   IF EXISTS (SELECT * FROM ##MyTempTable WHERE EventCode = 'Done')
      BREAK;  -- 'Done' row has finally been inserted and detected, so end this loop.

   PRINT N'The other process is not yet done.';  -- Re-confirm the non-done status to the console.
   WAITFOR DELAY '00:01:30';  -- Sleep for 90 seconds.

See Also