Return in Stored Procedure

Source: Internet
Author: User

A stored procedure can return not only the query results, but also an identifier indicating the success or failure of the stored procedure. We can use return to return this identifier, whether a stored procedure provides a return value or not,ProgramA return value is returned. sqlserver automatically returns a 0 value when the stored procedure is completed by default.

Return values can be returned using return, for example: return 100

Note:The returned value must be an integer!

This return statement is similar to the Return Statement in functions of other languages. After the return statement is executed, it exits from the stored procedure insteadCode.

What does return mean? Actually, I seldom use it when writing a stored procedure. Every time I create a new stored procedure, the template will end with a return, and every time I delete it.

Consider this problem. If the returned value is 0 by default, it means there is no error, but this is not very good. It is clear that there is a problem in the stored procedure, but it still returns 0, we must clearly understand the meaning of the returned value so that we do not get an unexpected return value. Therefore, when the logic is not met, you can return an identifier to determine whether the execution of the stored procedure is correct.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.