问题:
带有自增属性的列,无法直接执行 insert into 操作;
create table chenjch_tbs01(id int IDENTITY(1,1) NOT NULL,age int);
insert into chenjch_tbs01 values(1,1);
报错如下:
消息 8101,级别 16,状态 1,第 1 行
仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'chenjch_tbs01'中的标识列指定显式值。
insert into chenjch_tbs01(id,age) values(1,1);
消息 544,级别 16,状态 1,第 1 行
当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'chenjch_tbs01' 中的标识列插入显式值。
解决:
SET IDENTITY_INSERT chenjch_tbs01 ON
select * from sys.objects where type='U' and name='chenjch_tbs01'; ---object_id=980406762
select column_id,name from sys.columns where object_id=980406762 order by column_id;
insert into chenjch_tbs01(id,age) values(1,1);
欢迎关注我的微信公众号"IT小Chen"