debugsqlMinor
How to get all messages raised when a statement fails
Viewed 0 times
raisedfailsallstatementgetmessageshowwhen
Problem
Executing the below query will generate two error messages
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.
This is sample situation.
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.
Solution
This is expected behavior with
You'll need to use a client application (e.g. SQLCMD, PowerShell) to capture all error messages.
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.
Context
StackExchange Database Administrators Q#116119, answer score: 4
Revisions (0)
No revisions yet.