The throw statement in SQL Server2012 tries to compare RAISERROR and throw

Source: Internet
Author: User

SQL SERVER2012 implements a throw statement that resembles C # throws an exception. It is a small improvement to use the @ @ERROR before SQL Server2005, and to throw an exception after SQL Server2005 using RAISERROR ().

1.SQL server2005/2008, use RAISERROR and try ... Catch statement to throw an exception compared to the @ @ERROR to judge that has progressed a lot. But a very bad thing about using RAISERROR is that there is no way to return the number of rows that are really wrong.

--Incorrect number of rows returned using RAISERROR
beginTran
BEGINTRY
Select1/0;
Commit
ENDTRY

beginCatch
rollback
RAISERROR('Custom Error Messages', A,1)
PrintError_message ();--encountered a divisor error with zero.
EndCatchView Code

2. Using SQL SERVER2012 to add a new throw statement becomes much simpler. and correctly returns the line that is faulted, which saves a lot of time for long T-SQL statements.

--use throw to return the correct number of rows
beginTran
BEGINTRY
Select1/0;
Commit
ENDTRY

beginCatch
rollback;
Throw
EndCatchView Code

The throw statement in SQL Server2012 tries to compare RAISERROR and throw

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.