High on SQL!!!

Aug 19
### Error Handling in the SQL Code

​I would recommend coding in a couple scenarios in order to catch true errors during script deployment, particularly when we conduct a query that updates a section of data and fails. When this occurs, they must redo their work to tidy things up. Furthermore, it may compromise data integrity, causing database destruction. To avoid this, I always advise developers to encapsulate their SQL code in a template like—

 

BEGIN

BEGIN TRY

BEGIN TRAN

---Add SQL Logic here

COMMIT TRAN

END TRY

BEGIN CATCH

ROLLBACK TRAN

SELECT

ERROR_NUMBER() AS ErrorNumber

,ERROR_SEVERITY() AS ErrorSeverity

,ERROR_STATE() AS ErrorState

,ERROR_PROCEDURE() AS ErrorProcedure

,ERROR_LINE() AS ErrorLine

,ERROR_MESSAGE() AS ErrorMessage;

END CATCH

END;

 

Thanks ,

Zahid

 

Comments

There are no comments for this post.