仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时

如果想要给标识列显示的添加数据,可以使用如下的方法:

set identity_insert  PCInfo on--设置标识列可以显示添加数据
insert into PCInfo(PCId,PCUse,PCNote) values(100,1,'aaa')--PCId为标识列
set identity_insert  PCInfo off--设置标识列不可以显示添加数据

注意:要想显示的为某表的标识列显示添加数据,在insert语句中一定要在表后面显示要添加的字段,

如:PCInfo(PCId,PCUse,PCNote),如果只写PCInfo仍然不能为PCId显示的添加数据

原文地址:https://www.cnblogs.com/tianguook/p/2507797.html