BEGIN TRY
SELECT 1 / 0 AS Error;
END TRY
BEGIN CATCH
SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_STATE() AS ErrorState,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;
END CATCH;
BEGIN TRANSACTION [Tran1]
BEGIN TRY
-- sql statements(update/insert...)
COMMIT TRANSACTION [Tran1]
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION [Tran1]
SELECT ERROR_MESSAGE() AS ErrorMessage;
END CATCH
-- It is Transaction Control Language(TCL)
-- case1 (temporary)
BEGIN TRANSACTION
-- perform DML operation i.e. INSERT, UPDATE, DELETE
ROLLBACK -- goes to previous state
-- case2 (permanent)
BEGIN TRANSACTION
-- perform DML operation i.e. INSERT, UPDATE, DELETE
COMMIT -- Transaction is executed and hence change is done permanently