FIX: Add Constraint Causes Identity-Column Inserts to FailLast reviewed: May 1, 1997Article ID: Q136958 |
The information in this article applies to:
SYMPTOMSIf 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.
CAUSEThis problem only occurs if the identity field was added by using the ALTER TABLE statement.
WORKAROUNDMove 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.
STATUSMicrosoft 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 INFORMATIONThe 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |