Hi,
You are doing totally wrong and time taking approach. Following are the best and more optimized approach.
- Don't create temp table for storing temporary data.
1. You have to create Archive table only for first time then before archive you can delete all existing data from the archive table using below query.
DELET * From ArchiveTable
DBCC CHECKIDENT ('[ArchiveTable]', RESEED, 0);
2. Copy Data from original table to Archive table using below query.
INSERT INTO OriginalTable
(column_name(s))
SELECT column_name(s)
FROM ArchiveTable;
Please do let me know if still you having issue.