Error Handling and Check Constraints

  • 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?

  • 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.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • 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

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply