sqlsever自增字段插入值异常处理

不能在sqlsever自增字段中插入值,如果作此操作就会出现如下警告。
Cannot insert explicit value for identity column in table 't' when identity_insert is set to OFF.
这个错误消息提示我们,如果向 SQL Server 自增字段插入值,需要设置 identity_insert 选项为 on。
example:
create table dbo.t
(
id int identity(1,1) not null,
name varchar(50)
)
set identity_insert t on

insert into t (id, name) values(1, 'sqlstudy')

set identity_insert t off
注意的是,自增字段插入值后要记得要及时把 identity_insert 设置为 off。

posted @ 2015-04-14 16:47  forevermemory  阅读(521)  评论(0编辑  收藏  举报