MSsql里执行insert时报错“identity_insert off”的解决办法
问题描述: 公司数据库用的是微软的Sql Server,某天面临一个需求需要向一个不怎么更改的表里insert数据。当我去数据库insert的时候提示我identity_insert字段为off时无法完成insert操作。解决方案:
1
2
3
4
5
6
7
8
use database;
/*选择需要修改的数据库*/
set identity_insert tablename on;
/*先把该table的identity_insert字段打开,然后修改完毕后再关闭*/
INSERT INTO tablename (DriverNo,Location...)
VALUES (45,'31'...);
/*如果是字符型,记得加引号*/
set identity_insert DriverRouter off;
思考:
在identity_insert开启的时候,写保护,只有临时关闭才可以修改
页:
[1]