Suppose you have a set of codes and when a particular condition is true, you want to terminate or switch to another set of code, you can use Break commnad. I see sometimes people use return commnad for this. But there is a significant difference between these two. Consider this example
Usage of BREAK (select will be executed)
declare @i int set @i=1 while 1=1 begin print @i if @i>10 break set @i=@i+1 end select @i
Usage of RETURN (select will not be executed)
declare @i int set @i=1 while 1=1 begin print @i if @i>10 return set @i=@i+1 end select @i
So what happens is when break command is used, it just terminate the current block (created by if clause, while loop etc), but return will terminate the entire block
Tags: t-sql, sql_server, tsql, BRH, SQL Server, #TSQL, #SQLServer, break, return,