Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Why Use Error Handling? Expand / Collapse
Author
Message
Posted Wednesday, April 30, 2014 3:05 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, April 30, 2014 2:57 PM
Points: 68, Visits: 408
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.
Post #1566613
Posted Wednesday, April 30, 2014 3:17 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:56 PM
Points: 13,081, Visits: 12,545
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)
Post #1566615
Posted Thursday, May 1, 2014 4:54 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 5:38 AM
Points: 13,876, Visits: 28,274
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
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1566667
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse