Using a database table as a queue

前端 未结 9 2215
既然无缘
既然无缘 2020-12-02 07:45

I want to use a database table as a queue. I want to insert in it and take elements from it in the inserted order (FIFO). My main consideration is performance because I have

9条回答
  •  情歌与酒
    2020-12-02 08:39

    A very easy solution for this in order not to have transactions, locks etc is to use the change tracking mechanisms (not data capture). It utilizes versioning for each added/updated/removed row so you can track what changes happened after a specific version.

    So, you persist the last version and query the new changes.

    If a query fails, you can always go back and query data from the last version. Also, if you want to not get all changes with one query, you can get top n order by last version and store the greatest version I'd you have got to query again.

    See this for example Using Change Tracking in SQL Server 2008

提交回复
热议问题