FIX: Add Constraint Causes Identity-Column Inserts to Fail |
Q136958
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.
This problem only occurs if the identity field was added by using the ALTER TABLE statement.
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.
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.
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 : kbprogramming
Issue type : kbbug
Technology : kbSQLServSearch kbAudDeveloper kbSQLServ600
|
Last Reviewed: March 25, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |