【问题标题】:An explicit value for the identity column in table 'COM_MST' can only be specified when a column list is used and IDENTITY_INSERT is ON只有在使用列列表并且 IDENTITY_INSERT 为 ON 时,才能为表“COM_MST”中的标识列指定显式值
【发布时间】:2013-08-27 06:02:18
【问题描述】:

不知道为什么这段代码没有执行...

SET IDENTITY_INSERT COM_MST ON
GO
INSERT INTO COM_MST 
SELECT * FROM COM_MST_DEL

并显示错误

An explicit value for the identity column in table 'COM_MST' can only be specified when a column list is used and IDENTITY_INSERT is ON.

【问题讨论】:

  • 我总是很惊讶人们没有发现错误消息中间的 并意识到有 两个 条件他们必须履行。

标签: sql-server identity


【解决方案1】:

您必须在插入语句中指定列

【讨论】:

    【解决方案2】:
    SET IDENTITY_INSERT COM_MST ON
    GO
    INSERT INTO COM_MST 
    SELECT * FROM COM_MST_DEL
    

    在此您的 select 语句 SELECT * FROM COM_MST_DEL 可能返回的列多于表 COM_MST 中可用的列,还请确保在 Insert 语句中指定列名。

    查看An explicit value for the identity column in table can only be specified when a column list is used and IDENTITY_INSERT is ON SQL Server帖子中提出的解决方案

    【讨论】:

      猜你喜欢
      • 2011-07-08
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 2011-01-01
      • 2013-06-05
      • 2023-04-08
      • 1970-01-01
      • 2016-10-21
      相关资源
      最近更新 更多