Reputation: 4210
So I have a SQL Server table.
This table has a column that shows the datetime of when it was inserted.
How can I have something run that always deletes records that are 24 hours old?
Upvotes: 0
Views: 1595
Reputation: 613
I couple of things to add to this discussion...
For example: Comparing
date_created < dateadd(d,-1,GETDATE())
To
date_created < getdate()-1
Shows that the dateadd function adds considerable overhead to the evaluation and while it would be faster then scanning the PK it's always better to shoot for the fastest option altogether.
Upvotes: 3
Reputation: 8824
Yes, take a look at this: How to: Schedule a Job (SQL Server Management Studio)
then just schedule your query:
delete from table_name where date_created < dateadd(d,-1,GETDATE())
Upvotes: 3