Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSSQL record date/time auto delete

I want to delete records from a db table based on a time-stamp for each record. I would like to have it automatically delete records compared to a date/time interval without user intervention or admin intervention.

What would be the best way to go about this, I could create a process that runs in the background that does checks but that is extra work I want to avoid? Is there any libraries/web services I could use as templates?

like image 896
Ayo Avatar asked Feb 24 '09 16:02

Ayo


People also ask

How do I purge old data in SQL Server?

To delete data or log files from a databaseExpand Databases, right-click the database from which to delete the file, and then click Properties. Select the Files page. In the Database files grid, select the file to delete and then click Remove. Click OK.

Can you subtract time in SQL?

MySQL SUBTIME() FunctionThe SUBTIME() function subtracts time from a time/datetime expression and then returns the new time/datetime.


1 Answers

SQL Server Agent can do this for you.

Simply create a job with a regular schedule and the SQL you want to run. There is an easy to use wizard interface for job creation.

like image 85
Tomalak Avatar answered Sep 29 '22 05:09

Tomalak