MSSQL record date/time auto delete
Asked Answered
A

2

15

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?

Allethrin answered 24/2, 2009 at 16:45 Comment(0)
L
12

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.

Links answered 24/2, 2009 at 16:51 Comment(0)
W
0

Create a sql JOB with below query:

UPDATE [dbo].[User] WITH (ROWLOCK) SET active_flag=0 where lastlogindt < DATEADD(Day,-90,GETDATE())

Whiffet answered 26/12, 2019 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.