RESTART is a PostgreSQL reserved keyword used in three contexts: 1. ALTER SEQUENCE - resets an existing sequence generator so the next NEXTVAL call returns a specified or default start value.2. ALTER TABLE ... ALTER COLUMN ... RESTART WITH - resets the internal sequence that backs an IDENTITY column.3. TRUNCATE ... RESTART IDENTITY - empties a table and resets all associated identity/serial sequences so newly inserted rows start from the original or specified seed.Behavior- When WITH value is omitted, the sequence restarts at the START value originally defined for that sequence.- RESTART does not affect other sequence properties such as INCREMENT, MINVALUE, MAXVALUE, or CYCLE.- In TRUNCATE, RESTART IDENTITY applies to the target table and, when CASCADE is specified, also to all tables with foreign-key dependencies.Caveats- RESTART immediately sets the current value; concurrent sessions calling NEXTVAL may see gaps if they cached earlier values.- You need ownership or adequate privileges on the sequence or table to execute RESTART.- RESTART is not part of the ANSI SQL standard; behaviour and availability differ across RDBMSs.
sequence_name
(identifier) - Name of the sequence to resetWITH start_value
(integer, optional) - First value returned after restartTABLE_NAME
(identifier) - Table containing the identity column or being truncatedCOLUMN_NAME
(identifier) - Identity column to resetCASCADE | RESTRICT
(keyword, optional) - Propagate truncation to dependent tables or notALTER SEQUENCE, ALTER TABLE, IDENTITY columns, TRUNCATE, NEXTVAL, SETVAL
PostgreSQL 8.4 (ALTER SEQUENCE RESTART); TRUNCATE ... RESTART IDENTITY added in PostgreSQL 9.1
Use ALTER SEQUENCE seq_name RESTART; PostgreSQL restarts the sequence at its originally defined START value.
Yes. ALTER TABLE table_name ALTER COLUMN col_name RESTART WITH n; resets the backing sequence and sets the next generated value to n.
No. ALTER SEQUENCE and ALTER TABLE RESTART commands do not touch table data. Only TRUNCATE ... RESTART IDENTITY removes rows.
No. MySQL uses ALTER TABLE ... AUTO_INCREMENT = n and SQL Server uses DBCC CHECKIDENT to reseed identity columns. The RESTART keyword is PostgreSQL specific.