Delete a record from the database when the deadline is passed

Asked

Viewed 849 times

2

How can I automatically delete a record from the MYSQL database when it reaches a deadline? remembering I am using a data_termino attribute of type Date

1 answer

1

DELETE FROM table WHERE data_termino < '2017-09-21 00:00:00';

or if it is a higher date use > .. and so on

You can do something more automated for example: (last 6 months)

delete from table where data_termino name < DATE_SUB(NOW() , INTERVAL 6 MONTH)

if you want a break use the BETWEEN

  • and how would you take the current date as if it were from the system, to compare it to the end-date? Remembering the deletion has to be automatically executed by the DBMS without administrator interaction

  • Current date is NOW()

  • then it would look like this? DELETE FROM table WHERE data_termino < DATE_SUB(NOW())

  • what do you want to do? delete all records from now back?

  • if you run DELETE FROM table Where data_termino < NOW() . or is going to clear the table.

  • yes all records that have a lower end date than the current date

  • is exactly that there.. make a test before with Select to be sure :) but no mistake. hug.

  • To be automatic use the EVENT https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.