BUG: Err Msg 549 When Adding Foreign Key on Primary Key Column

Last reviewed: April 8, 1997
Article ID: Q153224

The information in this article applies to:
  • Microsoft SQL Server, versions 6.0 and 6.5
BUG# 13578 (6.0, 6.50) (sqlserver)

SYMPTOMS

Adding a foreign key constraint on a primary key column using ALTER TABLE can fail with the following error:

   Msg 549, Level 16, State 2: data exists in table '<db name>', database
   '<table>', that violates FOREIGN KEY constraint '<constraint name>'
   being added ALTER command has been aborted

This problem occurs when the child table has a multicolumn primary key already defined and both primary keys for the child and parent tables use non-clustered indexes.

The problem does not occur if:

  • The foreign key constraint was created using CREATE TABLE.
  • The foreign key column was not part of a primary key.
  • Both parent and child tables have primary keys that use clustered indexes.

WORKAROUND

Any of the following will allow you to work around the problem:

  • Create the foreign key constraint using CREATE TABLE.
  • Drop the existing primary key constraint on the child table , alter the table to create the foreign key constraint, and then recreate the primary key constraint.
  • Use clustered indexes for primary key of parent and child table.

STATUS

Microsoft has confirmed this to be a problem in Microsoft SQL Server version 6.0 and Microsoft SQL Server 6.5. This problem does not occur in Microsoft SQL Server 6.5 U.S. Service Pack 2. For more information, contact your primary support provider.


Additional query words: sysconstraints sysreferences
Keywords : kbbug6.00 kbbug6.50
Version : 6.0 6.5
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.