13.6. More Database Objects

Sequences

In SQL, a sequence is a database object that automatically generates a succession of values—note that this is a completely different meaning of the word “sequence” from its usage in XQuery, as we’ll see later. Sequence objects were first introduced in SQL:2003 and are useful whenever it’s necessary to produce a unique key value. Having the unique value generated inside the database, instead of in an external application, reduces the possibility of issues arising in areas such as performance and concurrency. Some SQL implementations may precompute the next values in a sequence and cache these ready for immediate use.

In some respects, a sequence is similar to an identity column in a table. However, unlike ...

Get Information Modeling and Relational Databases, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.