Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

database

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

like image 977
Matrix Avatar asked Oct 30 '09 10:10

Matrix


People also ask

Why do we need sequence in database?

A sequence is a database object that allows the automatic generation of values, such as check numbers. Sequences are ideally suited to the task of generating unique key values. Applications can use sequences to avoid possible concurrency and performance problems resulting from column values used to track numbers.

How do database sequences work?

A sequence is a database object which allows users to generate unique integer values. The sequence is incremented every time a sequence number is generated. The incrementation occurs even if the transaction rolls back, which may result in gaps between numbers.

Which type of data we can store in sequence database?

These databases collect all publicly available DNA, RNA and protein sequence data and make it available for free.

What is the protein sequence database?

The Protein database is a collection of sequences from several sources, including translations from annotated coding regions in GenBank, RefSeq and TPA, as well as records from SwissProt, PIR, PRF, and PDB. Protein sequences are the fundamental determinants of biological structure and function.


1 Answers

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.

like image 51
Stefan Steinegger Avatar answered Oct 14 '22 00:10

Stefan Steinegger