开发者

SQL Server 2005: Getting error when setting auto increment on one of two primary keys

开发者 https://www.devze.com 2023-01-08 15:42 出处:网络
I am getting an error \"Cannot insert explicit value for identity column in table \'table\' when IDENTITY_INSERT is set to OFF.\"开发者_开发技巧

I am getting an error "Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF."

开发者_开发技巧

The table has two primary key, one is set to auto-increment, one is set with value i passed into.

Is this possible in SQL Server 2005? or am i missing something?

Thanks alot in advance.


You are trying to insert a value into an identity column You can do this by

SET IDENTITY_INSERT TableName ON
INSERT INTO TableName() VALUES ()
SET IDENTITY_INSERT TableName OFF

http://msdn.microsoft.com/en-us/library/ms188059.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消