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 TRY

BEGIN TRAN

Add SQL Logic here

COMMIT TRAN

BEGIN CATCH

ROLLBACK TRAN

SELECT ERROR_LINE () AS LINE

,ERROR_NUMBER() AS ERROR_NUMBER

,ERROR_MESSAGE() AS MESSAGE

END CATCH

 

Thanks ,

Zahid

 

Comments

There are no comments for this post.