Skip to content
Advertisement

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

Advertisement

Answer

  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)
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement