QUIZ: RETURN in Transact SQL

Quiz: RETURN

On this quiz, when [NULL] is an option, interpret that as nothing is returned. Also, assume you have not changed the default batch separator in your SQL Server Management Studio installation.
  • RETURN
    GO

    PRINT 2;
    GO
  • RETURN

    PRINT 2;
    GO
  • IF 1 = 1
    BEGIN
        RETURN;
    END

    PRINT 2;
  • CREATE OR ALTER PROC dbo.test
    AS
        RETURN 1;
    GO

    EXEC dbo.test;
    GO

Learn more about RETURN

To see how other folks have done on the quiz and to read a discussion of each question, check out this post.

2 thoughts on “QUIZ: RETURN in Transact SQL

  1. Hi Kendra

    Not sure I agree with the answer to question 4. Whilst it is true that “Commands completed successfully” will appear in the messages window, but that wasn’t the question. The question is “Given this code, what will the procedure dbo.Test return?” and the procedure will definitely return the value 1 to anything that is willing to receive it (which is, admittedly, not very much in SSMS)…..so I stand by my answer of 1 🙂

    1. Oh, yes, you are correct. That is terrible wording and either answer is defensible. Language is difficult.

      I’ve changed this to “4) Given this code, what appear in the Messages window after you execute dbo.Test?” Hopefully that leads to a more clear *single* correct answer. I’ll note in the blog roundup the confusion on the question.

      The intent behind the question is simply to raise awareness that at first testing in SSMS, this might seem broken, but it’s just a limitation of the interface.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.