TRUNCATE ... RESTART IDENTITY
TRUNCATE ... RESTART IDENTITY is a SQL statement in the DML Statements category. TRUNCATE with options: RESTART IDENTITY resets auto-increment, CASCADE truncates child tables too. The syntax is TRUNCATE TABLE table_name RESTART IDENTITY [CASCADE];. It returns table truncated. A typical example: TRUNCATE TABLE log_entries RESTART IDENTITY; -- Empties table AND resets AUTO_INCREMENT counter TRUNCATE TABLE orders CASCADE; -- Also truncates related tables (PostgreSQL) -- Vs plain TRUNCATE: reset vs keep sequence A close relative is INSERT INTO, which inserts new rows into a table. A close relative is UPDATE, which modifies existing rows in a table. Always use WHERE to avoid updating all rows. A close relative is DELETE, which removes rows from a table. Always use WHERE to avoid deleting all rows. More about this category: Data Manipulation Language — INSERT, UPDATE, DELETE, REPLACE, MERGE. Related DML Statements entries: INSERT INTO, UPDATE, DELETE, REPLACE INTO, INSERT ... ON DUPLICATE KEY UPDATE, MERGE, INSERT INTO SELECT, UPSERT (PostgreSQL).