적용 대상:SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
분석 플랫폼 시스템(PDW)
Microsoft Fabric
의 SQL 분석 엔드포인트Microsoft Fabric
의 웨어하우스Microsoft Fabric 미리 보기의 SQL 데이터베이스
BREAK는 현재 WHILE 루프를 종료합니다. 현재 WHILE 루프가 다른 루프 내에서 중첩되는 경우 BREAK는 현재 루프만을 종료하고, 외부 루프의 다음 명령문에 제어가 제공됩니다.
BREAK는 일반적으로 IF 문 내에 있습니다.
Examples
SQL Server의 예
다른 선행 프로세스가 완료될 때 값이 필요한 테이블을 상상해 보세요.
WHILE (1=1)
BEGIN
IF EXISTS (SELECT * FROM ##MyTempTable WHERE EventCode = 'Done')
BEGIN
BREAK; -- 'Done' row has finally been inserted and detected, so end this loop.
END
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.
END
Azure Synapse 전용 SQL 풀의 예
DECLARE @sleeptimesec int = 1;
DECLARE @startingtime datetime2(2) = getdate();
PRINT N'Sleeping for ' + CAST(@sleeptimesec as varchar(5)) + ' seconds'
WHILE (1=1)
BEGIN
PRINT N'Sleeping.';
PRINT datediff(s, getdate(), @startingtime)
IF datediff(s, getdate(), @startingtime) < -@sleeptimesec
BEGIN
PRINT 'We have finished waiting.';
BREAK;
END
END