FIX: Add Constraint Causes Identity-Column Inserts to FailID: 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 : kbprg SSrvProg kbbug6.00 kbfix6.00.sp1
Version : winnt:6.0
Platform : winnt
Issue type :
Last Reviewed: July 20, 1999