Does SQL Server guarantee sequential inserting of an identity column?

后端 未结 5 1225
情话喂你
情话喂你 2021-02-13 15:12

In other words, is the following \"cursoring\" approach guaranteed to work:

  1. retrieve rows from DB
  2. save the largest ID from the returned records for later,
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-13 15:56

    The only time records might get inserted that you wouldn't get would be if someone turns the identity insert on and manually inserts a record to a skipped id (or in some cases to a negative number). This is a fairly rare occurance and generally would only be done by a system admin. Might be done to reinsert an accidentally deleted record for instance.

提交回复
热议问题