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:

Migrating (and Open-Sourcing) an Historical Codebase: SVN-to-Git

I have a SVN repo on my local machine that I have been shoving stuff into since before I knew how to use revision control systems properly (...