Friday, 4 January 2008

SQL 2005/2008 TRANSACTION in TRY/CATCH BLOCK

BEGIN TRY
BEGIN TRANSACTION

... your code here ...

COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
DECLARE @ErrorMessage as varchar(max)
SET @ErrorMessage = 'The error message is:' + (SELECT ERROR_MESSAGE())
RAISERROR(@ErrorMessage, 16, 1)
END CATCH

1 comment: