有很多关于收到错误的帖子:
"必须为表格#34中的标识列指定显式值; "当IDENTITY_INSERT设置为ON或复制用户时 正在插入NOT FOR REPLICATION标识列"
问题始终是用户正在尝试执行以下操作:
insert into table1 select * from table2
在我的情况下,我提供列名,但仍然收到错误。
编辑:我试图捕获标识列的原因是因为临时表是我最终将其他数据插入RC_Incoming
时的测试版本。我的算法是:
TempTable
作为RC_Incoming
TempTable
(让RecordID
自动生成)RC_Incoming
。代码:
<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]