zhangzhifeng

 

set identity_insert 表名 ON --允许对自增列Id插入指定数据
insert into table_name(Id,Name) values(1,\'test\')
set identity_insert 表名 OFF --关闭对自增列Id插入指定数据

注意:

1.set identity_insert只对当前会话生效。

2.set identity_insert 表名 ON 设置后,必须显示指定Id,否则插入错误。如insert into table_name values(\'111\')将报错。

   向自增ID插入指定值。 报错:“当 IDENTITY_INSERT 设置为 OFF 时,不能为表 \' \' 中的标识列插入显式值”。

   插入语句未显示指定ID。 报错:“仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表\' \'中的标识列指定显式值”。

分类:

技术点:

相关文章: