Sequence vs identity

后端 未结 6 920
南方客
南方客 2020-11-29 20:20

SQL Server 2012 introduced Sequence as a new feature, same as in Oracle and Postgres. Where sequences are preferred over identities? And why do we need sequence

6条回答
  •  孤城傲影
    2020-11-29 20:41

    Sequence and identity both used to generate auto number but the major difference is Identity is a table dependant and Sequence is independent from table.

    If you have a scenario where you need to maintain an auto number globally (in multiple tables), also you need to restart your interval after particular number and you need to cache it also for performance, here is the place where we need sequence and not identity.

提交回复
热议问题