Create Task Mysql Database

Asked

Viewed 1,394 times

2

I need to create a JOB (known in sqlserver) in a mysql database, first I would like to know if there is such a possibility, and if there is one, what would be the syntax?

I have a Table that holds a date column, I want the database to perform a task if the date equals the current date.

  • Do you want this to happen when? From time to time? When it is entered, updated?

  • Maniero, there is the possibility of me updating a table and at a certain time of the next day it update again ?

1 answer

4


Speak master so I found it for you, yes it has how to do job in mysql as it speaks on this site: http://www.sitepoint.com/how-to-create-mysql-events/

Something like this example:

DELIMITER $$

CREATE 
    EVENT `archive_blogs` 
    ON SCHEDULE EVERY 1 WEEK STARTS '2011-07-24 03:00:00' 
    DO BEGIN

        -- copy deleted posts
        INSERT INTO blog_archive (id, title, content) 
        SELECT id, title, content
        FROM blog
        WHERE deleted = 1;

        -- copy associated audit records
        INSERT INTO audit_archive (id, blog_id, changetype, changetime) 
        SELECT audit.id, audit.blog_id, audit.changetype, audit.changetime 
        FROM audit
        JOIN blog ON audit.blog_id = blog.id
        WHERE blog.deleted = 1;

        -- remove deleted blogs and audit entries
        DELETE FROM blog WHERE deleted = 1;

    END */$$

DELIMITER ;

Just adapt your need and good.

Adding Full Reference to Event: http://dev.mysql.com/doc/refman/5.5/en/create-event.html

Browser other questions tagged

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