开发者

How to poll a database using a stored procedure?

Using a stored procedure, how do I po开发者_C百科ll a table every 15 minutes (maybe longer)? Based on what that polling finds, I'll be inserting data into another table.


You should use the SQLAgent or some scheduler to run the procedure every 15 minutes.
A stored procedure is a transaction. You don't want one procedure just looping/waiting.

Is there a reason you don't want to use a trigger?


This isn't really a job for a stored procedure in my opinion. This sounds more like something for SQL Agent.

That said, you could run a stored procedure that used a WHILE loop along with WAITFOR and that should do what you're trying to do.

WHILE (1=1)
BEGIN
    -- Check your table, etc.

    WAITFOR DELAY '00:15:00.000'
END

An UPDATE/INSERT trigger could also be used for this, then you don't have to worry about anything constantly running and potentially failing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜