Hello All,Some T-SQL commands can fail with multiple errors. For example, if you try to disable a primary key constraint using ALTER TABLE t1 NOCHECK CONSTRAINT PK, you will get messages like:[quote]Msg 11415, Level 16, State 1, Line 341Object 'PK' cannot be disabled or enabled. This action applies only to foreign key and check constraints.Msg 4916, Level 16, State 0, Line 341Could not enable or disable the constraint. See previous errors.[/quote]However, in the code below, only the last message is printed. How can I print all the error messages?[code="sql"]USE tempdb;CREATE TABLE #t1(c1 INT CONSTRAINT PK PRIMARY KEY);BEGIN TRY ALTER TABLE #t1 NOCHECK CONSTRAINT PK; PRINT 'Primary key disabled'END TRYBEGIN CATCH PRINT ERROR_MESSAGE();END CATCH[/code]
↧