Home > database >  How to execute a Query every 2mins? in SQL
How to execute a Query every 2mins? in SQL

Time:03-30

I have this query that gives me the amount of created records every time I run it.

How do i do that automatically every 2 mins in SQL.

I have this,

Select COUNT (\*) from \[DB\].\[DB\].\[DB\] where Data1='01111111111111' order by 1 DESC

CodePudding user response:

 CREATE EVENT 'event_name'
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT '']
    DO event_body;

schedule: {
    AT timestamp [  INTERVAL interval] ...
  | EVERY 2 MINUTE
    [STARTS timestamp [  INTERVAL interval] ...]
    [ENDS timestamp [  INTERVAL interval] ...]
}

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

You can check how to use the other parameters in this mysql documentation

CodePudding user response:

i guess the only thing that u need is somthing like setInterval so : if u using js in your project you can run this code:

setInterval(function () {"do ajax call for your sql"}, 120000);

in the other hand you can use socket.io , socket.io keep you in touch with your sql unceasing

ps: between these 2 solution i highly recommended socket.io cause It is more efficient in terms of server

  •  Tags:  
  • sql
  • Related