Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
how to delete row after 30 days?

What I have tried:

how to delete row after 30 days?
Posted
Updated 30-Jun-19 20:03pm

Put one column to log data creation date like CreatedOn which contains same date and time when that record has been inserted

You can use below query to delete records which are older then 30 days

SQL
delete from TableName where CreatedOn < (SELECT DATE_SUB(now(), INTERVAL 30 DAY));


Let me know if you have any query or concern for same.
 
Share this answer
 
There is no automated way to remove "old" rows: you need to set an ExpiryDate column when you INSERT or UPDATE the row, and either check the expiry when you SELECT them, or run a regular task in your app to remove expired rows.
Me? I'd probably do expiry checks and not actually delete the rows, as I don't like discarding information. That's relatively simple: just add to your SeLECT command WHERE clause:
SQL
SELECT ... WHERE ExpiryDate >= Now() AND ...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900