Set AUTO_INCREMENT value through variable in MySql

后端 未结 1 1112
野的像风
野的像风 2021-01-12 20:00

I have a table with an auto_increment column. I save the last value of the column in another table called ids_tbl, and when mysql restarts, read the value from ids_tbl and r

相关标签:
1条回答
  • 2021-01-12 20:20

    Use the below code. This is working fine. And follow the MySQL prepared statement https://dev.mysql.com/doc/refman/5.7/en/sql-syntax-prepared-statements.html

    SET @max_id = (SELECT MAX(id) FROM `ids_tbl` );
    SET @sql = CONCAT('ALTER TABLE `outgoing_tbl` AUTO_INCREMENT = ', @max_id);
    PREPARE st FROM @sql;
    EXECUTE st;
    
    0 讨论(0)
提交回复
热议问题