본문 바로가기
DataBase

MySql - AUTO_INCREMENT 초기화 방법과 유의사항

by 맑은안개 2022. 9. 2.

MySql8.x AUTO_INCREMENT 초기화 방법

ALTER TABLE table_name AUTO_INCREMENT =1;
  • 위의 방법으로 AUTO_INCREMENT 값을 변경할 수 있으나, 데이터가 없는 경우에만 가능하다.

Note that you cannot reset the counter to a value less than or equal to any that have already been used. For MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum plus one. For InnoDB, if the value is less than the current maximum value in the column, no error occurs and the current sequence value is not changed.

  • 최신 ID가 5를 다음과 같이 가르키고, 위 처럼 1로 value값을 변경하는 경우, 변경되지 않는다.

예시

  • 하지만 최신 ID 보다 높은 값은 가능하다.
    ALTER TABLE table_name AUTO_INCREMENT = 10;

 

반응형