October 25, 2016 at 12:14 pm
I am new to writing Stored Procedures and having been reading up on Error Handling e.g. Throw and RaiseError.
My question is that why would I need to use Error Handling if we have Check Constraints which does the same thing? Or what can Error Handling do which Check Constraints lack?
October 25, 2016 at 12:34 pm
Check constraints will validate that data in a table follows certain rules.
Error handling will prevent errors from crashing a process by giving the option of following an alternate path if there's an error.
Both concepts are completely different things.
October 25, 2016 at 1:12 pm
What is the difference between a CHECK CONSTRAINT and error handling?
A CHECK CONSTRAINT will automatically throw an error in response to the insertion of invalid data.
TRY + CATCH can be used to handle (ie: suppress and programmaticaly respond to) an error.
THROW | RAISERROR can be used to programmatically raise an error.
BTW: This type of "explain the difference between" question is good for asking candidates during intermediate level interviews.
"Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho
November 22, 2016 at 9:11 am
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply