What is a sequence (Database)? When would we need it?

后端 未结 3 1918
暗喜
暗喜 2020-11-29 02:40

Why would we create a sequence even if there is a primary key?

3条回答
  •  失恋的感觉
    2020-11-29 03:34

    The primary key is a column in a table.

    The primary key needs a unique value, which needs to come from somewhere.

    The sequence is a feature by some database products which just creates unique values. It just increments a value and returns it. The special thing about it is: there is no transaction isolation, so several transactions can not get the same value, the incrementation is also not rolled back. Without a database sequence it is very hard to generate unique incrementing numbers.

    Other database products support columns that are automatically initialized with a incrementing number.

    There are other means to create unique values for the primary keys, for instance Guids.

提交回复
热议问题