The original: SQL transaction, in sql2000 to determine whether the execution is successful with @ @ERROR judgment
Put a SQL transaction in sql2000 to determine if execution succeeds with @ @ERROR
This thing is still a bit of a problem, sql2005 can use try. Catch, regardless of the error can be captured, and then in the rollback, very convenient, posted out drying
BEGIN TRANSACTION;
BEGIN TRY--try Execute SQL
SELECT 1/0;
END TRY
BEGIN catch--cache catch wrong
SELECT
Error_number () as ErrorNumber,--return error number
Error_severity () as errorseverity,--return severity
Error_state () as ErrorState,--Return error status number
Error_procedure () as Errorprocedure,--returns the name of the stored procedure or trigger in which the error occurred
Error_line () as ErrorLine,--Returns the line number in the routine that caused the error
Error_message () as errormessage;--returns the full text of the error message. The text can include values provided by any replaceable parameter, such as length, object name, or time
IF @ @TRANCOUNT > 0---Returns the number of active transactions for the current connection.
ROLLBACK TRANSACTION; --The transaction in error is to be rolled back
END CATCH;
IF @ @TRANCOUNT > 0---Returns the number of active transactions for the current connection.
Commit transaction;--the correct SQL, commit the transaction
GO
SQL transaction, in sql2000 to determine whether execution is successful with @ @ERROR judgment