Mysql regularly updates the value status of table field Columns

Source: Internet
Author: User

Now there are two more tables, tcm and doc;

Db_count:

Id count

1 220

2 300

3 220

4 222

5 240

Db_date:

Id t_date count

1 2012-09-10 17:04:07 220

2 2012-09-11 15:04:07 224

3 2012-08-20 11:04:07 225

4 2012-02-11 17:04:07 300

5 10:04:07 500

6 2012-09-12 17:04:07 300

--- The Stored Procedure changes the count value of the db_count table to 0;

DELIMITER //

Create procedure update_count ()

BEGIN

DECLARE m date;

DECLARE y CURSOR for select t_date from db_date;

Declare continue handler for sqlstate '000000' SET k = 1;

OPEN y;

FETCH y INTO m;

If sysdate ()> m THEN

UPDATE db_date t, db_count g SET g. count = 0 WHERE t. id = g. id;

End if;

CLOSE y;

END //

DELIMITER;

---- The event is executed at an interval of 1 second.

DELIMITER //

Create event my_count

On schedule every 1 second do

Begin

Call update_count ();

End //

DELIMITER;

Select * from db_count;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.