3

Executing the below query will generate two error messages

ALTER TABLE [MFClassProperty] DROP CONSTRAINT [FK_MFClassProperty_MFProperty]

Error messages are:

Msg 3728, Level 16, State 1, Line 3 'FK_MFClassProperty_MFProperty' is not a constraint. Msg 3727, Level 16, State 0, Line 3 Could not drop constraint. See previous errors.

If I use a try..catch block, then it shows only the last message.

  • Why isn't it moving to the catch block on the first error?
  • Is there any way to get all error messages?

This is sample situation.

7
  • TRY CATCH would always return last error message which is encountered.
    – Shanky
    Sep 25, 2015 at 9:39
  • 1
    then why its not end the process after the first error?
    – thejustv
    Sep 25, 2015 at 10:35
  • I dont know the code so cannot comment.
    – Shanky
    Sep 25, 2015 at 10:43
  • code attached in the question. While executing that query am getting two error messages
    – thejustv
    Sep 25, 2015 at 11:13
  • 1
    I posted an answer to a similar question: Catching two error messages/Throw into table
    – Dave Mason
    Sep 15, 2016 at 14:54

1 Answer 1

4

This is expected behavior with TRY/CATCH in T-SQL. The related Connect bug report was closed as "won't fix":

You'll need to use a client application (e.g. SQLCMD, PowerShell) to capture all error messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.