How to Reset an MySQL AutoIncrement using a MAX value from another table?

前端 未结 8 677
遥遥无期
遥遥无期 2020-12-08 07:04

I know this won\'t work, tried it in various forms and failed all times. What is the simplest way to achieve the following result?

ALTER TABLE XYZ AUTO_INCRE         


        
8条回答
  •  萌比男神i
    2020-12-08 07:23

    Use a Prepared Statement:

      SELECT @max := MAX(ID)+ 1 FROM ABC; 
    
      PREPARE stmt FROM 'ALTER TABLE ABC AUTO_INCREMENT = ?';
      EXECUTE stmt USING @max;
    
      DEALLOCATE PREPARE stmt;
    

提交回复
热议问题