Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Modifying columns
Modifying identities
Modifying sequences
10. Restarting sequences
Summary

Instruction

Very well done! Now, how about sequences? Can they be modified or removed? It turns out that they can! Let's say we have a sequence like this:

CREATE SEQUENCE standard_seq START WITH 1 INCREMENT BY 1;

The sequence generates subsequent integers for us. At some point, however, we deleted all rows with auto-generated values and we'd like the sequence to start generating numbers from 1 again. We can use the following syntax:

ALTER SEQUENCE standard_seq START WITH 1 RESTART;

The query above first sets the new starting value for sequence standard_seq to 1 and then uses RESTART to actually reset the current value to the starting value. Sound complicated? You can also use the simplified syntax:

ALTER SEQUENCE standard_seq RESTART WITH 1;

The code above works the same – it simply sets the current sequence value to 1. You can also restart a sequence using any other value. If you want to start over from 100, you just need to use:

ALTER SEQUENCE standard_seq RESTART WITH 100;

Exercise

The agency has created the sequence below:

CREATE SEQUENCE artist_numbers START WITH 1 INCREMENT BY 2;

Some values have already been generated. Your task is to start the sequence over from 1.