Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Sequences
11. Creating sequences
Summary

Instruction

Okay, great! We now know how to auto-generate integer columns with GENERATED ... AS IDENTITY. However, another similar mechanism is also available in most databases. The mechanism is known as a sequence object. As the name suggests, sequence objects automatically generate new numbers in a sequence. Have a look:

CREATE SEQUENCE first_seq
START WITH 1 INCREMENT BY 1;

You've probably guessed what this code does. It will create a sequence named first_seq, with the initial value of 1, that will be increased by 1 each time.

Note that a sequence can be created in a database independently of any table.

Exercise

Create a sequence named my_sequence, which starts from 100 and increases by 10.