If you run into the following error message:
An explicit value for the identity column in table ‘<TABLE_NAME>’ can only be specified when a column list is used and IDENTITY_INSERT is ON.
It can mean two things.

One you’ve not enabled identity insert on your table, meaning SQL Server will not let you insert into the Identity column.
This can be rectified with the following statement:
SET IDENTITY_INSERT table_name ON
And then turn it off again when done
SET IDENTITY_INSERT table_name OFF

However it can also mean that you are using for example INSERT INTO, in which cause the message tells you to specify the column names. This means using the following syntax:

INSERT INTO target_able_name (column_name1, column_name2…. column_nameN)
SELECT
YOUR_SELECT_LIST_WHICH_MATCHES_COLUMN_LIST
FROM source_table_name

I wasn’t aware of the latter syntax myself before I got the error message today. But then I learned a little something new today after all

 

原文: http://www.execsql.com/post/an-explicit-value-for-the-identity-column-in-table-can-only-be-specified-when-a-column-list-is-used-and-identity_insert-is-on

An explicit value for the identity column in table can only be specified when a column list is used and IDENTITY_INSERT is ON的更多相关文章

  1. 报错:Cannot insert explicit value for identity column in table 't' when identity_insert is set to OFF

    通常情况下,不能向 SQL Server 自增字段插入值,如果非要这么干的话,SQL Server 就会好不客气地给你个错误警告: Server: Msg 544, Level 16, State 1 ...

  2. Oracle :value too large for column "SCHEMA"."TABLE"."COLUMN" (actual: 519, maximum: 500)的解决方案

    原因:我是使用 CREATE TABLE XXX AS subquery 进行创建的数据表,主要是将相关的数据聚合在一起,然后通过导出为SQL脚本文件,进行导入到新库中,导致部分INSERT INTO ...

  3. JPA 报错解决方案 com.microsoft.sqlserver.jdbc.SQLServerException: Cannot insert explicit value for identity column in table 'test_db' when IDENTITY_INSERT is set to OFF.

    这种错误插入数据时就是hibernate的自增长字段生成规则应该用native 在字段前加入注解 @GeneratedValue(generator="generator") @G ...

  4. MySQL Error--InnoDB Table mysqlinnodb_index_stats has length mismatch in the column

    使用MySQL 5.7.24版本的安装文件替换MySQL 5.7.19版本的安装文件,数据库复制频繁中断,查看error日志发现下面错误: [Warning] InnoDB: Table mysql/ ...

  5. 错误解决Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: pers.zhb.domain.Student column: classno (should be mapped with insert="false" update="false")

    1.在学习hibernate的一对多多对一关系的时候,出现了一下错误: 2.错误原因: 这是因为在配置student.hbm.xml的配置文件的时候出现了将两个属性映射到同一个字段: <?xml ...

  6. SELECT TOP column FROM table [ORDER BY column [DESC]]

    如果想返问表中行的子集,仅需要返回特定数量的记录,而不管符合条件的行有多少.要返回排在前面的值,可以有两个选择:指定固定数量的行,或者指定总行数的百分比.SQL Server不对这些数据做任何分析,共 ...

  7. [每日一题] OCP1z0-047 :2013-07-15 drop column

    如下实验: gyj@OCM> Create table emp( 2    Empno     number(4)    not null, 3    First_name  varchar2( ...

  8. Sql Server 语句

    ##目录 #####清除缓存 DBCC FREEPROCCACHE; DBCC DROPCLEANBUFFERS; SELECT stock.IdStock, stock.Descr FROM [In ...

  9. yii2 数据库操作(转)

    开始使用数据库首先需要配置数据库连接组件,通过添加 db 组件到应用配置实现("基础的" Web 应用是 config/web.php),DSN( Data Source Name ...

随机推荐

  1. Laravel5 控制器

    Request 一.取值 1.取值 echo $request->input('name','这是默认值'); 2.取得所有值 $array=$request->all(); 3.判断值是 ...

  2. 考了3年,工作四年,零基础在职终于拿到CFA证书

    大家都知道CFA Charterholder是独有的全球公认的投资管理从业人员高职业水平和道德水准的有力证明,是金融界卓越专业成就的象征:CFA资格强调和遵循极其严格的职业操守和道德准则,世界各主要发 ...

  3. Redis “瘦身”指南

    code[class*="language-"], pre[class*="language-"] { background-color: #fdfdfd; - ...

  4. PHP的ntohl网络字节序函数及相关知识

    PHP与C服务器的socket通信,在做数据转换的时候,PHP没有提供对应将网络字节序和机器字节序相互转换的程序,但是根据函数的意义,我们可以做相应的转换来实现这一函数: function ntohl ...

  5. 网时|细数被鹿晗热点效应带火的心机boy们

    今天上班早高峰的地铁格外的宽敞,不知道是不是因为大家都被鹿晗关晓彤的甜蜜暴击到已经忘了上班这码事了.本以为是为了新戏<甜蜜暴击>做宣传,结果工作室都相继承认,他们倒是甜蜜了,暴击全给粉丝了 ...

  6. Python自学笔记-map和reduce函数(来自廖雪峰的官网Python3)

    感觉廖雪峰的官网http://www.liaoxuefeng.com/里面的教程不错,所以学习一下,把需要复习的摘抄一下. 以下内容主要为了自己复习用,详细内容请登录廖雪峰的官网查看. Python内 ...

  7. webpack2使用ch8-loader解析less less自动添加浏览器前缀

    1 目录结构  安装依赖 "less": "^2.7.2","less-loader": "^4.0.3", 2 web ...

  8. ch2-vue实例(new Vue({}) 属性与方法 声明周期)

    Vue 实例1 每个Vue.js都是通过创建一个Vue的根实例启动的 var vm = new Vue({}) 2 扩展Vue构造器,用预定义选项创建可复用的组件构造器 var MyComponent ...

  9. Sql Server合并多行询数据到一行:使用自连接、FOR XML PATH('')、STUFF或REPLACE函数

    示例表 tb 数据如下 id value ----- 1 aa 1 bb 2 aaa 2 bbb 2 ccc SELECT id, [val] = ( SELECT [value] + ',' FRO ...

  10. 【转载】使用CSS将图片转换成黑白(灰色、置灰)

    文章转载自 张鑫旭-鑫空间-鑫生活 http://www.zhangxinxu.com/ 原文链接:http://www.zhangxinxu.com/wordpress/?p=2547原文摘要: . ...