mysql 定時更新表欄位列的值狀態

來源:互聯網
上載者:User

   現在又兩個表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

  ---預存程序變更db_count表count值為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;

  ----事件,事件間隔為1秒,進行執行該事件

  DELIMITER //

  CREATE EVENT my_count

  ON SCHEDULE EVERY 1 second do

  begin

  call update_count();

  end //

  DELIMITER;

  select * from db_count;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.