Skip to main content
adicionou 1 caractere ao conteúdo
Fonte Link
AndersonBS
  • 3,2mil
  • 3
  • 24
  • 44

Você pode criar um EVENT!

CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Exemplo:

SET GLOBAL event_scheduler = ON;

DELIMITER $
CREATE EVENT eraseData 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2014-11-22 23:59:59' -- precisa ser no futuro
    DO BEGIN 
        DELETE FROM db.tabela; -- apaga os dados
    END
$ DELIMITER;DELIMITER ;

Você pode criar um EVENT!

CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Exemplo:

SET GLOBAL event_scheduler = ON;

DELIMITER $
CREATE EVENT eraseData 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2014-11-22 23:59:59' -- precisa ser no futuro
    DO BEGIN 
        DELETE FROM db.tabela; -- apaga os dados
    END
$ DELIMITER;

Você pode criar um EVENT!

CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Exemplo:

SET GLOBAL event_scheduler = ON;

DELIMITER $
CREATE EVENT eraseData 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2014-11-22 23:59:59' -- precisa ser no futuro
    DO BEGIN 
        DELETE FROM db.tabela; -- apaga os dados
    END
$ DELIMITER ;
adicionou 40 caracteres ao conteúdo
Fonte Link
AndersonBS
  • 3,2mil
  • 3
  • 24
  • 44

Você pode criar um EVENT!

CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Exemplo:

SET GLOBAL event_scheduler = ON;

DELIMITER $
CREATE EVENT eraseData 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2014-11-22 23:59:59' -- precisa ser no futuro
    DO BEGIN 
        --DELETE removeFROM dadosdb.tabela; da-- tabelaapaga aquios dados
    END
$ DELIMITER;

Você pode criar um EVENT!

CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Exemplo:

SET GLOBAL event_scheduler = ON;

DELIMITER $
CREATE EVENT eraseData 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2014-11-22 23:59:59' -- precisa ser no futuro
    DO BEGIN 
        -- remove dados da tabela aqui
    END
$ DELIMITER;

Você pode criar um EVENT!

CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Exemplo:

SET GLOBAL event_scheduler = ON;

DELIMITER $
CREATE EVENT eraseData 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2014-11-22 23:59:59' -- precisa ser no futuro
    DO BEGIN 
        DELETE FROM db.tabela; -- apaga os dados
    END
$ DELIMITER;
adicionou 40 caracteres ao conteúdo
Fonte Link
AndersonBS
  • 3,2mil
  • 3
  • 24
  • 44

Você pode criar um EVENT!

CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Exemplo:

SET GLOBAL event_scheduler = ON;

DELIMITER $
CREATE EVENT eraseData 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2014-11-22 23:59:59' -- precisa ser no futuro
    DO BEGIN 
        -- remove dados da tabela aqui
    END
$ DELIMITER;

Você pode criar um EVENT!

CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Exemplo:

DELIMITER $
CREATE EVENT eraseData 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2014-11-22 23:59:59'
    DO BEGIN 
        -- remove dados da tabela aqui
    END
$ DELIMITER;

Você pode criar um EVENT!

CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Exemplo:

SET GLOBAL event_scheduler = ON;

DELIMITER $
CREATE EVENT eraseData 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2014-11-22 23:59:59' -- precisa ser no futuro
    DO BEGIN 
        -- remove dados da tabela aqui
    END
$ DELIMITER;
Fonte Link
AndersonBS
  • 3,2mil
  • 3
  • 24
  • 44
Carregando