DB/명령프롬프트 - mysql

[MySQL] auto_increment 초기화방법

congs 2023. 3. 29. 16:15
alter table 테이블명 auto_increment = 1;
set @count = 0; //변수만들기
update 테이블명 set 변경할칼럼명 =@count:=@count+1;
mysql> alter table guide auto_increment = 1; 

mysql> set @count = 0;

mysql> update guide set gu_num=@count:=@count+1;

mysql> select * from guide;
+--------+---------+------------+------------+
| gu_num | gu_year | gu_pr_num  | gu_st_num  |
+--------+---------+------------+------------+
|      1 | 2020    | 2010160001 | 2020160001 |
|      2 | 2020    | 2010160001 | 2020160002 |
|      3 | 2020    | 2011123001 | 2020123001 |
|      4 | 2020    | 2011123001 | 2020123002 |
|      5 | 2020    | 2006456001 | 2020456001 |
+--------+---------+------------+------------+