Event schedule every week : Schedule « Event « SQL / MySQL






Event schedule every week

     
mysql>
mysql> CREATE TABLE EVENTS_INVOKED
    ->       (EVENT_NAME      VARCHAR(20) NOT NULL,
    ->        EVENT_STARTED   TIMESTAMP NOT NULL);
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql>
mysql> CREATE EVENT SUNDAYS
    ->    ON SCHEDULE EVERY 1 WEEK
    ->       STARTS TIMESTAMP(CASE DAYNAME(NOW())
    ->          WHEN 'Sunday'    THEN NOW()
    ->          WHEN 'Monday'    THEN NOW() + INTERVAL 6 DAY
    ->          WHEN 'Tuesday'   THEN NOW() + INTERVAL 5 DAY
    ->          WHEN 'Wednesday' THEN NOW() + INTERVAL 4 DAY
    ->          WHEN 'Thursday'  THEN NOW() + INTERVAL 3 DAY
    ->          WHEN 'Friday'    THEN NOW() + INTERVAL 2 DAY
    ->          WHEN 'Saturday'  THEN NOW() + INTERVAL 1 DAY
    ->       END, '15:00:00')
    ->       ENDS TIMESTAMP(
    ->          CASE DAYNAME(CONCAT(YEAR(CURDATE()),'-12-31'))
    ->          WHEN 'Sunday'    THEN
    ->             CONCAT(YEAR(CURDATE()),'-12-31')
    ->          WHEN 'Monday'    THEN
    ->             CONCAT(YEAR(CURDATE()),'-12-31') - INTERVAL 1 DAY
    ->          WHEN 'Tuesday'   THEN
    ->             CONCAT(YEAR(CURDATE()),'-12-31') - INTERVAL 2 DAY
    ->          WHEN 'Wednesday' THEN
    ->             CONCAT(YEAR(CURDATE()),'-12-31') - INTERVAL 3 DAY
    ->          WHEN 'Thursday'  THEN
    ->             CONCAT(YEAR(CURDATE()),'-12-31') - INTERVAL 4 DAY
    ->          WHEN 'Friday'    THEN
    ->             CONCAT(YEAR(CURDATE()),'-12-31') - INTERVAL 5 DAY
    ->          WHEN 'Saturday'  THEN
    ->             CONCAT(YEAR(CURDATE()),'-12-31') - INTERVAL 6 DAY
    ->        END, '15:00:00')
    ->    DO INSERT INTO EVENTS_INVOKED VALUES ('SUNDAYS', NOW());
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> drop table EVENTS_INVOKED;
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql>
mysql>

   
    
    
    
    
  








Related examples in the same category

1.Event schedule start with case clause
2.ON SCHEDULE AT NOW()
3.ON COMPLETION PRESERVE
4.ON SCHEDULE EVERY 1 MONTH
5.ON SCHEDULE EVERY 3 MONTH