Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2005
    Posts
    92

    Unanswered: Catching violation of UNIQUE KEY constraint in stored procedure

    Dear All,

    I have a stored procedure which bulk inserts records into a table based on a passed in variable that contains comma separated values of record Ids.

    However I have a constraint on the table ensuring that value-pairs in 2 columns must be unique (as a person can not be twice on the same project)

    Since I insert the passed in person Ids in a loop, Id like to catch if this constraint has been violated and skip that specific cycle if it has but do commit the rest.

    Not sure if this can be done, and if yes could someone let me know the SQL syntax and structure please?

    Am I explaining this clearly?

    Thanks in advance all comments are much appreciated!

  2. #2
    Join Date
    Jul 2002
    Posts
    229
    Can you test on @@ERROR ?

  3. #3
    Join Date
    Mar 2005
    Posts
    92
    Cool, seems to do it, forgot about it, I actually had it in there. No I just collect the Ids and return them as output csv to let user know!

    Thanks for the idea!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •