When you have been running Audit Trail Classic for a while the main audit table may become very large. The large the table the slower the lookup of records and adding of new audited changes. You may want to delete older entries in the audit table that are no longer needed. This functionality is built into Audit Trail Classic. (See  Delete Historical Transactions on page 19 of the user guide)


You may not want to delete the old records but instead archive them to another database table or even another database. This needs to be a manual process. 

(Moving to another database is beyond the scope of this article. One method is to simply do a backup of your existing database and a restore on the new one. Or you can have a linked server and perform the following SQL to that server directly instead)


If you want to move rows of the audit table to a new table then you can run the following statement. This is based on date but you could base it on transaction number or any other variable.


SELECT * INTO zd_Audit_bak
FROM zd_Audit

WHERE zd_Audit.DateChanged < '2017-01-01'


This will copy the records that were changed before 1st January 2017 into the backup table. If you then want to delete the records in the main table you can run the following:


DELETE FROM zd_Audit

WHERE zd_Audit.DateChanged < '2017-01-01'


Alternatively use the Delete Historical Transactions functionality to do this for you.