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。
为了明天所以选择坚定的执着今天。