ALTER SEQUENCE (Alter Sequence)

Last updated: 2026-11-04

ALTER SEQUENCE (Alter Sequence)

ALTER SEQUENCE retunes an existing sequence: changing its step, bounds, or cache, restarting its counter, or binding it to a column. It is the tool for resetting numbering after a data repair, or for leaving gaps between batches of ids.

Kindcommand
Example LanguageSQL

📝 Syntax

ALTER SEQUENCE [IF EXISTS] <sequence name>
[AS <data type>]
[INCREMENT [BY] <step>]
[MINVALUE <min> | NO MINVALUE]
[MAXVALUE <max> | NO MAXVALUE]
[START [WITH] <start>]
[RESTART [WITH] <restart value>]
[CACHE <cache size>]
[CYCLE | NO CYCLE]
[OWNED BY <table>.<column> | NONE]

⚙️ Parameters

RESTART WITHSets the next value to be issued
INCREMENT BYChanges the increment step
MINVALUE / MAXVALUEAdjusts the value range
OWNED BYBinds the sequence to a column, or NONE to unbind

Returns:No return value. Changes take effect for subsequent nextval() calls right away.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

DROP TABLE
DROP SEQUENCE
CREATE SEQUENCE
CREATE TABLE
INSERT 0 1
ALTER SEQUENCE
ALTER SEQUENCE
INSERT 0 1
id  |    title    
----+-------------
  1 | before alter
100 | after alter

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QHow do I reset a sequence back to 1?
ARun ALTER SEQUENCE seq_name RESTART WITH 1; — the next value issued is 1, while previously issued numbers are not reused.
QDoes changing the increment scramble existing numbers?
ANo. Numbers already issued stay as they are; only values issued from that point on follow the new step.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏