Raul Gómez
Raul Gómez

Reputation: 1

How to execute a Query every 2mins? in SQL

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

Upvotes: 0

Views: 265

Answers (2)

Arian Fm
Arian Fm

Reputation: 387

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

Upvotes: 0

Pedro Barreto
Pedro Barreto

Reputation: 401

 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

Upvotes: 1

Related Questions