How to catch those two message errors in SQL?

  • Here's an instance.

    If you go to add a Foreign key to a child table where the referenced column in the parent table is not a primary key, you will receive 2 errors.

    Msg 1776, Level 16, State 0, Line 1

    There are no primary or candidate keys in the referenced table 'Mosaic.dbo.ProgramRecoType' that match the referencing column list in the foreign key 'FK_ProviderServiceCountryRecommendation_ProgramRecoType_ProgramRecoType_ID_ProgramRecoType_ID'.

    Msg 1750, Level 16, State 0, Line 1

    Could not create constraint. See previous errors.

    However, if you try/catch - you only catch the second error - resulting in the display of

    Msg 1750, Level 16, State 0, Line 1

    Could not create constraint. See previous errors.

    Which does me no good? Is there actually a way to catch this?

    Doug

  • Nope. Catch just gets the last one.

    Try Catch is more meant to capture runtime issues with data or security/access.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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