MySQL periodically updates the value status of a table field column

Source: Internet
Author: User

Now again two tables Tcm,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 2012-09-11 10:04:07 500

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

---stored procedure changes db_count table count value is 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 ' 02000 ' 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;

----event with an event interval of 1 seconds to execute the event

DELIMITER//

CREATE EVENT My_count

On SCHEDULE EVERY 1 second do

Begin

Call Update_count ();

End//

DELIMITER;

SELECT * from Db_count;

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.