I am running a daily Job that updates a fact table. Before copying the new data I create a backup in a table that is identically and only creates a timestamp additionally.
The main purpose for the backup table is to identify potential issues and to see an earlier version.
Now, I want to limit the number of backups available so I was considering deleting older backups that I don't need any longer.
I would like to keep the following backups:
- Everything in the last 14 days
- The last one before 21 days, 28 days
- Afterwards monthly
- Afterwards yearly
What is the most elegant way to do this in t-sql?
A challenge I forsee is also that for whatever reason not a backup on a specific day is available but for example for -1 or -2 days.
Thanks for any advices.
I tried a delete script that would delete the records between the dates that I'd like to keep.