Mysql event to delete expired rows

0

I'm trying to create an event to delete rows, that the column date is with the date expired, that is smaller than the current one.

I was trying with the following command:

create event e on schedule every 1 day do delete from Reserve where date < curdate();

But then I tested it by adding a line with a date already passed and changing every 1 day to every 1 second But I did not succeed ...

Could someone help me with the correct query for my problem?

    
asked by anonymous 11.04.2016 / 01:51

1 answer

5
CREATE EVENT IF NOT EXISTS 'dbName'.'eventName'
ON SCHEDULE
    EVERY 1 DAY // or 1 HOUR
COMMENT 'Description'
DO
    BEGIN

    DELETE FROM 'dbName'.'TableName' WHERE 'DateCol' < NOW();

    END

Amigão adapt this code above! (as you did not make the fields available I can not adapt for you: /)

REMEMBERING TO ACTIVATE MySQL Event Scheduler

Source: link

    
15.04.2016 / 02:21