Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Why Use Error Handling?


Why Use Error Handling?

Author
Message
dhechle
dhechle
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 425
I have always believed best practice when writing stored procedures or any SQL code is to include error handling. I was challenged today though as to why include error handling in a certain ETL project being written at the moment, I think its quite obvious that if there is some sort of failure then the load should roll back instead of leaving it in a non consistent state.

I was then asked as to what scenarios might a failure occur, there is the obvious of network blips, servers failing, databases failing, deadlocks occurring, table being accidentally dropped, can you think of any specific reasons as to why you have used error handling in any projects and when it has provided useful.

thanks in advance.
Sean Lange
Sean Lange
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16542 Visits: 16999
dhechle (4/30/2014)
I have always believed best practice when writing stored procedures or any SQL code is to include error handling. I was challenged today though as to why include error handling in a certain ETL project being written at the moment, I think its quite obvious that if there is some sort of failure then the load should roll back instead of leaving it in a non consistent state.

I was then asked as to what scenarios might a failure occur, there is the obvious of network blips, servers failing, databases failing, deadlocks occurring, table being accidentally dropped, can you think of any specific reasons as to why you have used error handling in any projects and when it has provided useful.

thanks in advance.


Well gosh...you are talking an ETL process. That means it is an automatic process right? Wouldn't business like to be informed if something didn't work? Let's say your scenarios of a table being dropped happened. If you didn't have error handling how long would the process keep crashing before somebody noticed?

What a strange challenge. This is like asking "why do you have car insurance?" or "why do you wear a seatbelt?". 99.99999% of the time it isn't necessary, but that one time when the "OH S..." happens it is better to be prepared by being able to handle the issue instead of just crashing.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Grant Fritchey
Grant Fritchey
SSCoach
SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)SSCoach (17K reputation)

Group: General Forum Members
Points: 17572 Visits: 32256
One argument against error handling in T-SQL is that there is already error handling in the calling application. To which I'll respond that there are unique error events within SQL Server best handled within SQL Server such as a deadlock (assuming we're talking about TRY/CATCH here). But not all processes within T-SQL have to have error handling. That said, a multi-step ETL process done within T-SQL, yeah, that's a place where I'd probably put error handling and validations that everything is working.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search