Primary keys - the basics
Single-column primary keys
Multicolumn primary keys
Auto-increment columns and sequences
25. Retrieving data from sequences
Revision

Instruction

Good. Once we create a sequence, we can use a special instruction to retrieve the next value for it. The code varies depending on the database, so don't worry if it's different from the one we presented below.

SELECT nextval('first_seq');

The above code will select the next value for the sequence named first_seq. It is possible to associate a sequence with values in a column, but we'll discuss it in another part of our course. For now, just remember what sequences are.

Exercise

Select the next value for your new sequence my_sequence.

Stuck? Here's a hint!

Type

SELECT nextval('my_sequence');

Console

Code editor

Result

TableConsole