给标识列显示的添加数据(IDENTITY_INSERT 为 ON)

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

set identity_insert  表名 on  --设置标识列能够显示添加数据
insert into 表 (字段1,字段2,字段3) values (值1,值2,值3)  --字段1为标识列
set identity_insert  表名 off  --添加完数据之后记得设置标识列不能够显示添加数据

注意:要想显示的为某表的标识列显示添加数据,在insert语句中必定要指定所要插入数据的列,如:INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....),若是只写插入的值仍然不能显示的添加数据。ide

相关文章
相关标签/搜索