Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating EVENTS in SQL Server

I want to execute a query at a specific time. In MySQL we use events for that, example is as follows:

CREATE EVENT myevent
    ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
    DO
      UPDATE myschema.mytable SET mycol = mycol + 1;

Please let me know how to do the same in SQL Server. Thanks.

PS : Sorry if its a repeated question. I tried searching for some time but didn't get it in SQL Server

like image 922
StackAddict Avatar asked Mar 28 '26 18:03

StackAddict


1 Answers

  1. You can use Sql server agent for this task and you can schedule there. Its easy way.
  2. Another one is "waitfor time" check this link http://msdn.microsoft.com/en-IN/library/ms187331.aspx (and you need to create a trigger with while loop logic and there wait for time is useful)
  3. Another one create a bat file and schedule that in windows scheduler (if you are using sql sever express edition)
like image 104
Muthu Avatar answered Mar 31 '26 11:03

Muthu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!