Question

There are 2 .NET services which use 2 SQL Server databases. I am currently using SQL Express so the maximum database size is an issue.

When the size approaches the 10GB limit (or some record limit), I would like to automatically delete the oldest X amount of records to free up some space.

This is not a production environment and I REALLY don't need the old data, i just want to keep the data "fresh".

SHould this be done at the service level? I can modify my services to periodically check spaceused and execute a manual "clean up" (Whether it's a delete, archive, etc.). I'm not sure how do this on the SQL level however.

Thanks

Was it helpful?

Solution

Since you are using SQL Express, you will need to do this at the service level on some schedule. You will first need to delete the rows out of the table(s) that you want to purge the data from. Something like:

delete BigOleTable where LoggedDate < dateadd(yy,-1,getdate())

that will get rid of stuff older than a year.

Then, you will need to shrink the database.. so, this depends on your recovery model. If you're in full recovery, you'll need to backup the transaction log. and then issue a shrinkdatabase as Tanner alluded to above.

OTHER TIPS

You can create a job that does this or better use SSIS (see this: http://technet.microsoft.com/en-us/library/ms181153%28v=sql.105%29.aspx).

You can use this http://technet.microsoft.com/en-us/library/ms188776.aspx procedure to query the space used and if it exceeds a thesshold you could delete data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top