The statement defines a block of SQL code that is typically used in the IF and while statements
Declare @num int ;Set @num=0; while @num<Tenbegin Set @num=@num+1; Print 'Hello Word'End
Conditional Judgment statement, where else is optional
if (Selectfrom where name=' Zhang San ') = 1 Print ' the sex of Zhang San is: male ' Else Print ' the sex of Zhang San is: female '
Declare @num int ;Set @num=0; while @num<Tenbegin Set @num=@num+1; Print 'Hello Word' if @num=2 Continue if @num=5 BreakEnd
Description: This example outputs 5 lines Hello Word
This statement is used to unconditionally transfer the execution order of statements to user-defined lable
Declare @num int;Set @num=0; Echo:Print 'Hello Word'Set @num=@num+1; while @num<Tenbegin GotoEchoEnd
The statement is used to unconditionally exit a query or a procedure
Declare @num int ;Set @num=0; while @num<Tenbegin Set @num=@num+1; Print 'Hello Word' if @num=5 returnEnd
The statement is used to define a time of day, executing a block of statements. WAITFOR DELAY ' time ' indicates how long it will take to wait, and waitfor when to wait for the moment to execute.
Example: Output ' Hello word ' after 10 seconds
waitfor ' 00:00:10 ' Print ' Hello Word ' -- or Print ' Hello Word ' waitfor ' 00:00:10 '
Example: 12:00 clock output ' Hello word '
waitfor ' 12:00:00 ' Print ' Hello Word ' -- or Print ' Hello Word ' waitfor ' 12:00:00 '
The flow control statements in SQL Server are described here.
Flow control statements in SQL Server