定时器触发数据库事件

Suppose I have a table with the current users logged in on my website. And if I there isn't any "activity" from one of his/her username in a time interval it would be deleted from the table.

What would be the easiest way to implement this functionality?

Besides using batch files or something like that.

I searched but database triggers can't be timed programmed, at least from what I gathered.

Usually you would have something like this:

  • A table would have a column named something like last_activity which stores a timestamp of when the user last visited a page

  • You check via a query if a user has been active within a certain amount of time (ex: WHERE last_activity - current_time < 60 [active in the last minute])

Assuming your RDBMS supports them (you don't specify), using a scheduled job. In SQL Server's case, this would be a SQL Agent job.

Failing that using a windows scheduled task.