IDENTITY_INSERT设置为OFF时为什么插入时出错?
如何在SQL Server 2008中正确打开它?是通过使用SQL Server Management Studio吗?
SQL Server Management Studio
我已经运行了这个查询:
SET IDENTITY_INSERT Database. dbo. Baskets ON
然后,我在控制台中收到一条消息,指出命令已成功完成。但是,当我运行该应用程序时,它仍然给我显示以下错误:
Cannot insert explicit value for identity column in table 'Baskets' when IDENTITY_INSERT is set to OFF.
通过SQL按照MSDN
SET IDENTITY_INSERT sometableWithIdentity ON INSERT INTO sometableWithIdentity (IdentityColumn, col2, col3, ...) VALUES (AnIdentityValue, col2value, col3value, ...) SET IDENTITY_INSERT sometableWithIdentity OFF
完整的错误消息会告诉您确切的问题是什么…
当IDENTITY_INSERT设置为OFF时,无法为表'sometableWithIdentity'中的Identity列插入显式值。
IDENTITY_INSERT
'sometableWithIdentity'