Sql 插入自定义主键

  在遇到数据库设计是自增的主键,且须要插入自定义的主键Id时,这个时候若是直接Insert的话,将会发生错误,错误提示信息:数据库

当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'XXX' 中的标识列插入显式值。数据库设计

须要手动设置 IDENTITY_INSERT 为 ON.ide

语法:spa

set identity_insert [TableName] on 
INSERT INTO [TableName] ('字段') VALUES('')
set identity_insert [TableName] off
相关文章
相关标签/搜索