FIX: Add Constraint Causes Identity-Column Inserts to Fail

Last reviewed: May 1, 1997
Article ID: Q136958

The information in this article applies to:
  • Microsoft SQL Server, version 6.0
BUG# NT: 11057 (6.00)

SYMPTOMS

If you add a constraint to a table, it resets the identity, causing it to insert zeros in the identity column for all subsequent table inserts.

CAUSE

This problem only occurs if the identity field was added by using the ALTER TABLE statement.

WORKAROUND

Move the data into a holding place with a SELECT INTO. Drop and recreate the table with the CONSTRAINT or IDENTITY in place from the beginning. Or, you can use a trigger temporarily to perform the check function.

STATUS

Microsoft has confirmed this to be a problem in SQL Server version 6.0. This problem was corrected in Service Pack 1 for SQL Server version 6.0. For more information, contact your primary support provider.

MORE INFORMATION

The following script demonstrates this problem:

   create table test (f1 int)
   go
   insert into test values (12)
   go
   alter table test add f2 identity(14,2)
   go
   alter table test add constraint testcnst check (f1 < 15)
   go
   insert into test values(6)
   insert into test values(7)
   insert into test values(8)


Additional query words: sql6 tsql
Keywords : kbbug6.00 kbfix6.00.sp1 kbprg SSrvProg
Version : 6.0
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: May 1, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.