• Another reason to name your constraints is to help debug applications. A foreign key violation message states which column(s) in the key table were violated but doesn't tell you the referencing table or column names. My standard for naming foreign keys is as follows:

    FK_<RefTableName>$<RefColumn1>$<RefColumnN>

    Since the error message does show the contraint name, I get all the tables and columns involved in the error without having to step through every line of code in my script or application.

    BTW, I use $ instead of underscores because some people (myself excluded) use underscores in their object names.

    Bryant E. Byrd, MCDBA

    SQL Server DBA/Systems Engineer

    Intellithought, Inc.

    bbyrd@intellithought.com

    [font="Tahoma"]Bryant E. Byrd, BSSE MCDBA MCAD[/font]
    Business Intelligence Administrator
    MSBI Administration Blog