High on SQL!!!

Aug 19
### Error Handling in the SQL Code

​I would suggest developer for coding in couple scenario in order to capture actual error while script deployment especially when we execute a query that modifies portion of data and fails. This requires redoing their works to clean it up when this happens. Also, it potentially breaks data integrity that damages the databases. In order to avoid that I always suggest developers to wrap up their SQL code using 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.