Reset auto increment column value in script mysql
Posted
by Lucia
on Stack Overflow
See other posts from Stack Overflow
or by Lucia
Published on 2010-05-12T20:56:56Z
Indexed on
2010/05/12
21:04 UTC
Read the original article
Hit count: 280
mysql
|auto-increment
Hi,
I have two mysql tables, one needs to start its auto-increment column id with the last value of the last inserted row in the other table (plus 1).
According to mysql manual you can restart the value of an auto increment column like this:
mysql> ALTER TABLE tbl AUTO_INCREMENT = 100;
However, this is not possible:
mysql> ALTER TABLE tb2 AUTO_INCREMENT = (SELECT MAX(id) FROM tbl1);
I need to perform something like this because I'm filling the tables using a script. Is there another way to achieve it?
© Stack Overflow or respective owner