Saturday, November 14, 2009

Try/Catch in T-SQL

Applied from SQL Server 2005

BEGIN TRY
BEGIN TRAN
--Your T-SQL code here
COMMIT TRAN
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000);
SELECT @ErrorMessage = ERROR_MESSAGE();
ROLLBACK TRAN;
RAISERROR(@ErrorMessage, 16, 1);
END CATCH

No comments:

Post a Comment

Oracle Query