I saw how dba does this in several different companies, and it always seems to use the following format:
- Backup table
- Drop any indexes
- Select the rows you want to keep in the temp table
- Trim Source Table
- Insert (into source table) from temp table
- Recover Indexes
The advantage of this approach is that this update is not written to the logs, so they do not fall into thousands of deleted records. It is also faster.
The downside is that the update is not written to the logs, so your only option is to restore the backup.
You should consider keeping the house in place. If the above is too scary, then you can also use the house to display the database for a certain time.
In MSSQL, you can create a daily task that will delete the first 1000 lines of your query. To steal Adamβs request -
DELETE TOP 1000 FROM WHERE DATEADD table (year, 2, CreateDate) <GETDATE ()
It would be very safe and get rid of your data in three months or so safe, and they would also save the db size in the future.
Your database will use this space in the future, but if you want to restore the space, you will need to compress the database. Read if you are wondering if this is worth it, depends on the amount of recovery space compared to the total db size.
Chanoch
source share