Friday, March 9, 2012

ExceptionHandling in T-SQL?

Hi all,

Is there any concept of exception handling in T-SQL while writing Stored Procedures, plz. help me with this issue. I'm using SQL Server 2000

Hello Trid,

No, there is no structural error handling in 2000 so to speak. There are several ways to perform error handling in 2000, with the most common being to test the value of @.@.ERROR for a non-zero value, then send control to a handler lable for rollback etc.

if (@.@.error <> 0)

goto error_handler

return (0)

error_handler:

if (@.@.trancount > 0)

rollback tran

return (-1)

Cheers

Rob

|||

To back up what Robert said, T-SQL did not have a rich set of error handling capabilities in 2000, whatsoever. You have to deal with the error message on the client end. So be careful to check for and close any transactions you might have started when you get error messages back and want to stop the batch.

|||

Thank you Robert :)

No comments:

Post a Comment