Set AUTO_INCREMENT value programmatically

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2010-04-29T23:50:05Z Indexed on 2010/04/29 23:57 UTC
Read the original article Hit count: 135

Filed under:

So this works...

ALTER TABLE variation AUTO_INCREMENT = 10;

But I want to do this;

ALTER TABLE variation AUTO_INCREMENT = (SELECT MAX(id)+1 FROM old_db.varaition);

but that doesnt work, and neither does;

SELECT MAX(id)+1 INTO @old_auto_inc FROM old_db.variation 
ALTER TABLE variation AUTO_INCREMENT = @old_auto_inc;

So does anyone know how to do this?

( I'm trying to ensure that AUTO_INCREMENT keys dont collide between an old and a new site and need to do this automatically. So I can just run a script when the new db goes live )

© Stack Overflow or respective owner

Related posts about mysql