I have a table ActivityTable and i want to move some records to a Archive table and then delete those moved records from the main table ie the ActivityTable.
I am doing the following
INSERT INTO ArchiveTable
([Id] ,
[Name] ,
[Key] ,
[RegDate] ,
SELECT top 1000
[Id] ,
[Name] ,
[Key] ,
[RegDate] ,
FROM ActivityTable
WHERE registrationDate < cast(cast(dateadd(day, -10, getutcdate()) as Date) as DateTime)
DELETE
FROM ActivityTable
WHERE registrationDate < cast(cast(dateadd(day, -90, getutcdate()) as Date) as DateTime)
How can i be sure that the top 1000 that have been selected will the the exact 1000 that are deleted from the Activity Table ?
New contributor
Stacey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.