Question: I have a table which has two attributes: ID & Datetime when that record was created.

How can I make a trigger (procedure?) to delete a record after, say, 1 day?

I want a task which executes itself every X time instead of manually having to do it.

Answer: 
I suggest you to use SQL Server agent and write a stored procedure that deletes every rows that date is passed one day.

You can find how to use Sql server agent jobs here in this [link](https://learn.microsoft.com/en-us/sql/ssms/agent/schedule-a-job).

And the stored procedure like :

```
CREATE  PROCEDURE DeleteRows()
AS
BEGIN
DELETE FROM mytable
WHERE (DATEDIFF(DAY,  DATEADD(day, -1, DateColum), GETDATE())) >= 1
END

```

---

Edit :
The number 1 in where statement is days. you can change it to what you want to use.
You could create a SQL Job to run after one day (or daily as you want.) and execute a specified stored procedure that carries a simple delete statement.

Follow the next topic:-

<http://technet.microsoft.com/en-us/library/ms190268.aspx>