Skip to content

Instantly share code, notes, and snippets.

@powolnymarcel
Forked from irazasyed/reset_id_column.sql
Created April 24, 2020 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save powolnymarcel/df91b1f9e705e7a24f9a43d716deb1dd to your computer and use it in GitHub Desktop.
Save powolnymarcel/df91b1f9e705e7a24f9a43d716deb1dd to your computer and use it in GitHub Desktop.
MySQL: Reset id column to auto increment from 1
-- your_table: The table to modify
-- id: The id field/column to reset
SET @num := 0;
UPDATE your_table SET id = @num := (@num+1);
ALTER TABLE your_table AUTO_INCREMENT =1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment