There are many posts about getting the error:
"Explicit value must be specified for identity column in table" "either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column"
The problem is always that the user is trying to do something like:
insert into table1 select * from table2
In my case, I AM supplying column names, but still getting that error.
EDIT: The reason I'm trying to capture the identity column is because the temporary table is a test version of when I will ultimately insert other data into RC_Incoming
. My algorithm is:
- Create
TempTable
as a clone ofRC_Incoming
- Insert data from some other table into
TempTable
(lettingRecordID
be auto generated) - Make sure everything looks right
- If ok, then do it for realz -- insert in to
RC_Incoming
.
Code:
<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>
I'm still getting:
Error Executing Database Query. [Macromedia][SQLServer JDBC Driver][SQLServer]Explicit value must be specified for identity column in table '#TempTable_______________________________________________________________________________________________00000000066E' either when IDENTITY_INSERT is set to ON or when a replication user is inserting into a NOT FOR REPLICATION identity column.
RC_Incoming
already has data in it, and has the exact same structure (done in 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]