Set AUTO_INCREMENT value programmatically

前端 未结 4 2035
我在风中等你
我在风中等你 2021-01-06 05:20

So this works...

ALTER TABLE variation AUTO_INCREMENT = 10;

But I want to do this;

ALTER TABLE variation AUTO_INCREMENT = (         


        
4条回答
  •  不知归路
    2021-01-06 06:05

    I don't know if this is a good idea, but could you do it with 2 queries in a server side language, for example, PHP?

    $incrementStep = Db::query('SELECT MAX(id)+1 FROM old_db.varaition');
    
    Db::query('ALTER TABLE variation AUTO_INCREMENT = ' . (int) $incrementStep);
    

    Assuming that Db::query is a magic query method that returns exactly what you want, every time :)

提交回复
热议问题