Posts Tagged ‘mysql’

Mysql preserving autoincrement values and adding auto_increment

Programming | Posted by Gauthier
Sep 30 2013

This was a difficult query to come by. Just a book mark for future reference, and hopefully this will help someone else.
Originally the answer was here http://stackoverflow.com/questions/7995427/1062-duplicate-entry-1-for-key-1-no-duplicate-entries-found

SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;

ALTER TABLE Some_Table modify column uid int(11) auto_increment;

ALTER TABLE Some_Table AUTO_INCREMENT=SomeNumber;

SET SQL_MODE=”;