尝试将条目从备份表还原到主表
So some background. I have a pair of tables that store 'Application Information' for prospective employees.
The main table is displayed with PHP/SQL and there is a link to 'Delete' an application from the table.
INSERT INTO ResultsOLD SELECT * FROM Results WHERE Results.id = '$IDin'
DELETE FROM Results WHERE Results.id = '$IDin' AND Timestamp = '$INts'
The above entries copy the data to the backup table (old app storage) and deletes the entry from the Main table.
I am now trying to write a recovery page, so that an entry can be returned from the Backup table, back into the Main table (No deletion from Backup Table). I have the following SQL query:
INSERT INTO Results SELECT * FROM ResultsOLD WHERE ResultsOLD.id = '$IDin'
But when I try to run this query off of the new page, it gives an error. I have tried researching the error but I do not understand what it is saying (I am somewhat new to SQL).
This is the error I get:
An explicit value for the identity column in table 'Results' can only be specified when a column list is used and IDENTITY_INSERT is ON.
Is this because I am using the ID in the WHERE, which is the Primary Key? Also when I reinsert the data from the ResultsOLD table, I want to assign a new ID (Primary Key) to the entry but keep everything else intact. The ID is auto-increment, but I think because I am using the ID as the WHERE, it might be trying to insert that also?
所以有些背景知识。 我有一对用于为潜在员工存储“应用程序信息”的表。 p>
主表与PHP / SQL一起显示,并且从表中有一个“删除”应用程序的链接 。 p>
INSERT INTO ResultsOLD SELECT * FROM Results WHERE Results.id ='$ IDin'
DELEL FROM Results WHERE Results.id ='$ IDin'AND Timestamp =' $ INts'
code> pre>
上述条目将数据复制到备份表(旧的应用程序存储)并从主表中删除该条目。 p>
我现在正在尝试编写一个恢复页面,以便可以从备份表返回一个条目,返回主表(不从备份表中删除)。 我有以下SQL查询: p>
INSERT INTO结果SELECT * FROM ResultsOLD WHERE ResultsOLD.id ='$ IDin'
code> pre>
\ n 但是当我尝试从新页面运行此查询时,它会出错。 我已经尝试过研究错误,但我不明白它的含义(我对SQL有些新意)。 p>
这是我得到的错误: p>
表'结果'中的标识列的显式值只能在使用列列表且IDENTITY_INSERT为ON时指定。 p>
这是因为我在使用ID WHERE,哪个是主键? 此外,当我重新插入ResultsOLD表中的数据时,我想为该条目分配一个新ID(主键),但保持其他所有内容不变。 ID是自动递增的,但我认为因为我使用ID作为WHERE,它可能也试图插入它? p>
div>
I found something for that on the Internet: http://forums.databasejournal.com/showthread.php?9438-Turning-IDENTITY_INSERT-ON&p=21383#post21383