What is T-SQL Statement Blocks?

While researching something, I can through an MSDN article that says:

Exits unconditionally from a request or procedure. RETURN is immediate and complete and can be used anywhere to exit a procedure, batch or block . Statements following RETURN are not executed.

The documentation did not come close to the specific situation that I was studying. After reading it, I realized that I did not understand the Return statement and, more specifically, the definition of β€œ statement blocks ” as I thought. So that...

What is the t-sql "block"? Are they Begin ... End like brackets in C #, { ... } , or something else?

Thanks!

+6
source share
2 answers

They come in different tastes (try, catch), but overall they look like

 BEGIN PRINT 'I am a block' RETURN PRINT 'I am still in a block but you will not see me' END PRINT 'Too late, we returned from the above block' 
+5
source

I would agree that this proposal in the documentation is misleading.

RETURN will not just exit the most immediate BEGIN END block (which can be nested), but will return from the entire function or procedure, and I'm not sure if this means leaving the batch - maybe in SSMS with a GO delimiter it will continue run later games (I will need to check this). GO is a client thing, so I'm not sure how useful this concept is in practice.

+1
source

Source: https://habr.com/ru/post/896352/


All Articles