Check Constraints with User Defined Messages

  • I'm familiar with using sp_addmessage to generate user-defined error messages and triggering them with RAISERROR from my sp's.

    Can a CHECK CONSTRAINT be created that, when triggered, returns a specific user-defined message vs. the generic message 547 (UPDATE/INSERT statement conflicted with COLUMN CHECK constraint...) ?

    Thanks,

    Bryan

  • Bryan Whitaker (1/16/2009)


    I'm familiar with using sp_addmessage to generate user-defined error messages and triggering them with RAISERROR from my sp's.

    Can a CHECK CONSTRAINT be created that, when triggered, returns a specific user-defined message vs. the generic message 547 (UPDATE/INSERT statement conflicted with COLUMN CHECK constraint...) ?

    Thanks,

    Bryan

    The best you can get is to name the constraint as close as possible to the message you want but that is a hack.

    The real solution is to TRAP the error on the Client and act (bubble up the right exception message) accordingly!


    * Noel

Viewing 2 posts - 1 through 2 (of 2 total)

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