Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Primary keys - the basics
Single-column primary keys
Multicolumn primary keys
Auto-increment columns and sequences
Revision

Instruction

Okay, great. You should know that there are also some databases which do not have the AUTO_INCREMENT or IDENTITY columns. Instead, they use special objects called sequences. They are able to generate new numbers in a sequence, as the name suggests. Take a look:

CREATE SEQUENCE first_seq 
START WITH 1 INCREMENT BY 1;

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

Exercise

Let's do a quick exercise on creating sequences. Create a sequence with the name my_sequence which starts from 100 and increases the number by 10 each time.

Stuck? Here's a hint!

Type

CREATE SEQUENCE my_sequence 
START WITH 100 INCREMENT BY 10;