set IDENTITY_INSERT on 和 off 的设置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了set IDENTITY_INSERT on 和 off 的设置相关的知识,希望对你有一定的参考价值。
qlserver 批量插入记录时,对有标识列的字段要设置 set IDENTITY_INSERT 表名 on,然后再执行插入记录操作;插入完毕后恢复为 off 设置
格式:
set IDENTITY_INSERT 表名 on
set IDENTITY_INSERT 表名 off
举例:
set IDENTITY_INSERT peoplePworkpositiontype on
insert peoplePworkpositiontype(id,workpositiontype,workpositiontypeid) values(1 , ‘平台‘ , 1 )
insert peoplePworkpositiontype(id,workpositiontype,workpositiontypeid) values(2 , ‘陆地‘ , 2 )
insert peoplePworkpositiontype(id,workpositiontype,workpositiontypeid) values(3 , ‘海上‘ , 3 )
go
set IDENTITY_INSERT peoplePworkpositiontype off
set IDENTITY_INSERT peoplePstatetype on
insert peoplePstatetype(id,nowstatetype,nowstatetypeid) values(1 , ‘出海‘ , 1 )
insert peoplePstatetype(id,nowstatetype,nowstatetypeid) values(2 , ‘出差‘ , 2 )
insert peoplePstatetype(id,nowstatetype,nowstatetypeid) values(3 , ‘公司‘ , 3 )
insert peoplePstatetype(id,nowstatetype,nowstatetypeid) values(4 , ‘会议‘ , 4 )
go
set IDENTITY_INSERT peoplePstatetype off
go
以上是关于set IDENTITY_INSERT on 和 off 的设置的主要内容,如果未能解决你的问题,请参考以下文章
SET IDENTITY_INSERT ON|OFF 的解惑
如何使用来自 Access VBA 的直通查询执行 SET IDENTITY_INSERT ON/OFF?
SQL Server 错误:“无法为标识列插入显式值”,即使我 SET IDENTITY_INSERT ON