ก๊วนซอฟท์แวร์ </softganz> SoftGang (Gang Software)

Web &amp; Software Developer Gang.

Renumber Existing Rows of Auto Increment

by Little Bear @17 ส.ค. 69 13:36 ( IP : 171...109 ) | Tags : MariaDB

SET @count = 0; UPDATE table_name SET id_column = (@count := @count + 1); ALTER TABLE table_name AUTO_INCREMENT = 1;

Warning: Only do this if the column is not being used as a foreign key by other tables. Changing primary keys will break historical relational mappings unless you have configured ON UPDATE CASCADE

For deeper configuration details regarding persistent sequences, check out the MariaDB AUTO_INCREMENT Documentation.

Relate topics