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. [Oracle]理解undo表空间

    一.回退段介绍 在Oracle数据库中,当某个事物对数据进行修改时,Oracle首先将数据的原始值保存到一个回退段中.一个事物只能将它的回退信息保存到一个回退段中,而多个并行事物可以使用同一个回退段. ...

  2. Training little cats poj3735

    Training little cats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9299   Accepted: 2 ...

  3. HDU1223 Order Count 动态规划 组合数

    动态规划+组合数+大数 #include<cstdio> #include<cstdlib> #include<iostream> #include<algo ...

  4. c# gdi+输出成不同mime类型的图片

    /// <summary> /// 通过图片的mime类型得到相应的编码器 /// </summary> /// <param name="mimeType&q ...

  5. PPLB条码打印

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. 开源API集成测试工具 Hitchhiker v0.2更新 - 压力测试

    Hitchhiker 是一款开源的 Restful Api 集成测试工具,支持Schedule, 数据对比,压力测试,可以轻松部署到本地,和你的team成员一起管理Api. 详细介绍请看: http: ...

  7. Java—Day5课堂练习

    package com.lovo.classes;import java.util.Scanner;public class day5Test {    public static void main ...

  8. Tomcat 笔记-目录简介

    bin:启动和关闭tomcat的bat文件 conf:配置文件 server.xml该文件用于配置server相关的信息,比如tomcat启动的端口号,配置主机(Host) web.xml文件配置与w ...

  9. 217. Contains Duplicate (leetcode)

    Given an array of integers, find if the array contains any duplicates. Your function should return t ...

  10. DNS over TLS到底有多牛?你想知道的都在这儿

    DNS over TLS,让电信.移动等各种ISP无法监视你的浏览轨迹...... SSL证书有助于客户端浏览器和网站服务器之间的加密连接. 这意味着在连接期间,所有的通信和活动都被遮蔽. 但通常意义 ...