I'm trying to alter some tables with constraints and for production environment I need some kind of Try/Catch with "print" functions, not commons sql errores. How can i do this? I tried with this:
BEGIN TRY
My command
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();
-- Use RAISERROR inside the CATCH block to return error
-- information about the original error that caused
-- execution to jump to the CATCH block.
RAISERROR (@ErrorMessage, -- Message text.
@ErrorSeverity, -- Severity.
@ErrorState -- State.
);
END CATCH;
but it doesnt work. I changed the table's name to one that doesnt exists and the result was a typical message.
Thanks in advance
My source: http://msdn.microsoft.com/en-us/library/ms178592%28v=sql.90%29.aspx
