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
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
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
Browser other questions tagged mysql sql
You are not signed in. Login or sign up in order to post.
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
– fabricio b.
Current date is NOW()
– Thiago Loureiro
then it would look like this? DELETE FROM table WHERE data_termino < DATE_SUB(NOW())
– fabricio b.
what do you want to do? delete all records from now back?
– Thiago Loureiro
if you run DELETE FROM table Where data_termino < NOW() . or is going to clear the table.
– Thiago Loureiro
yes all records that have a lower end date than the current date
– fabricio b.
is exactly that there.. make a test before with Select to be sure :) but no mistake. hug.
– Thiago Loureiro
To be automatic use the EVENT https://dev.mysql.com/doc/refman/5.7/en/event-scheduler.html
– Motta