Reputation: 195
In sql server I need to make an archive system, at the end of every month I want to move all rows that posted in last month to the table named with month name, but also delete all existing data first from that target table (as you see this old data posted since one year ago, so I don't need it anymore).
My questions:
1- what is the better way to do this, drop the table itself then create a new one with select-into sentence, or delete all rows using delete sentence then inset the new rows from orginal table. (with the huge data I think this may make a difference)
2- How I can do that operation automatically, Is there any triggers based on time ?, or somthing in asp.net or server can do this ?.
Thanks for help.
Upvotes: 0
Views: 164
Reputation: 163
You can also create a cron/scheduler in windows which runs at the end of the month and which executes a procedure which does your job.
Upvotes: 0
Reputation: 83
Use the TRUNCATE TABLE statement, this deletes everything from the table but keeps the structure
You can set up a job in SQL Server using SQL Agent to run the job periodically
Upvotes: 3