'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
Solution 1:[1]
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
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pedro Barreto |
| Solution 2 | Arian Fm |
