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