This blog is moved to
http://amalhashim.wordpress.com
Showing posts with label rollback. Show all posts
Showing posts with label rollback. Show all posts

Wednesday, January 21, 2009

Try - Catch in Sql Server 2005

  • A TRY Block - the TRY block contains the code / script that might cause an exception

  • A CATCH Block - if an exception occurs from one of the statements in the TRY block, control is branched to the CATCH block, where the exception can be handled, logged, and so on.

BEGIN TRY

BEGIN TRANSACTION

stmts...

END TRAN

END TRY
BEGIN CATCH

IF @@TRANCOUNT > 0
ROLLBACK TRAN

END CATCH