即使指定了列名,SET IDENTITY_INSERT也不起作用(coldfusion)

时间:2015-10-21 20:19:16

标签: sql sql-server coldfusion identity-insert

有很多关于收到错误的帖子:

  

"必须为表格#34中的标识列指定显式值;   "当IDENTITY_INSERT设置为ON或复制用户时   正在插入NOT FOR REPLICATION标识列"

问题始终是用户正在尝试执行以下操作:

insert into table1 select * from table2

在我的情况下,我提供列名,但仍然收到错误。

编辑:我试图捕获标识列的原因是因为临时表是我最终将其他数据插入RC_Incoming时的测试版本。我的算法是:

  1. 创建TempTable作为RC_Incoming
  2. 的克隆
  3. 将其他表中的数据插入TempTable(让RecordID自动生成)
  4. 确保一切正常
  5. 如果没问题,那就去实现 - 插入RC_Incoming
  6. 代码

    <cfquery datasource="#LOCAL.DataSource#">
        IF OBJECT_ID('tempdb.dbo.##TempTable') IS NOT NULL
            DROP TABLE ##TempTable
        ELSE
        DBCC CHECKIDENT ([##TempTable], RESEED, 1);
        CREATE TABLE ##TempTable
        (   
            [RecordID] [INTEGER] IDENTITY NOT NULL,
            [StudentID] [varchar](15) NOT NULL,
            [CourseNumber] [varchar](6) NOT NULL,
            [CompDateTime] [datetime] NOT NULL,
            [SystemInfo] [varchar](250) NULL,
            [WriteTime] [datetime] default GETDATE() NULL,
            PRIMARY KEY CLUSTERED 
            (
                [StudentID], [CourseNumber], [CompDateTime]
            )
            WITH
            (
                PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = ON, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON
            )
        )
    </cfquery>
    
    
    <cfquery datasource="#LOCAL.DataSource#">
        SET IDENTITY_INSERT ##TempTable ON
        INSERT INTO ##TempTable
            (
                RecordID
                ,StudentID
                ,CourseNumber
                ,CompDateTime
                ,SystemInfo
                ,WriteTime
            )
        SELECT  RecordID
                ,StudentID
                ,CourseNumber
                ,CompDateTime
                ,SystemInfo
                ,WriteTime
         FROM   RC_Incoming
    </cfquery>
    

    我还在:

      

    执行数据库查询时出错。 [Macromedia] [SQLServer JDBC   驱动程序] [SQLServer]必须为标识列指定显式值   在表中   &#39; #TempTable _______________________________________________________________________________________________ 00000000066E&#39;当IDENTITY_INSERT设置为ON或复制用户时   插入NOT FOR REPLICATION标识列。

    RC_Incoming已包含数据,并且具有完全相同的结构(在SQL Server Management Studio中完成):

    CREATE TABLE dbo.[RC_Incoming]
    (
        [RecordID] [INTEGER] IDENTITY NOT NULL,
        [StudentID] [varchar](15) NOT NULL,
        [CourseNumber] [varchar](6) NOT NULL,
        [CompDateTime] [datetime] NOT NULL,
        [SystemInfo] [varchar](250) NULL,
        [WriteTime] [datetime] default GETDATE() NULL,
        PRIMARY KEY CLUSTERED 
        (
            [StudentID], [CourseNumber], [CompDateTime]
        )
        WITH
        (
            PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = ON, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON
        ) ON [PRIMARY]
    ) ON [PRIMARY]
    

0 个答案:

没有答案