<i id='0E1zT'><tr id='0E1zT'><dt id='0E1zT'><q id='0E1zT'><span id='0E1zT'><b id='0E1zT'><form id='0E1zT'><ins id='0E1zT'></ins><ul id='0E1zT'></ul><sub id='0E1zT'></sub></form><legend id='0E1zT'></legend><bdo id='0E1zT'><pre id='0E1zT'><center id='0E1zT'></center></pre></bdo></b><th id='0E1zT'></th></span></q></dt></tr></i><div id='0E1zT'><tfoot id='0E1zT'></tfoot><dl id='0E1zT'><fieldset id='0E1zT'></fieldset></dl></div>
<tfoot id='0E1zT'></tfoot>
  • <legend id='0E1zT'><style id='0E1zT'><dir id='0E1zT'><q id='0E1zT'></q></dir></style></legend>

    <small id='0E1zT'></small><noframes id='0E1zT'>

        • <bdo id='0E1zT'></bdo><ul id='0E1zT'></ul>
      1. 如何使用另一个表中的 MAX 值重置 MySQL AutoIncrement?

        时间:2023-07-18

      2. <legend id='sHTKI'><style id='sHTKI'><dir id='sHTKI'><q id='sHTKI'></q></dir></style></legend>

            <small id='sHTKI'></small><noframes id='sHTKI'>

              <i id='sHTKI'><tr id='sHTKI'><dt id='sHTKI'><q id='sHTKI'><span id='sHTKI'><b id='sHTKI'><form id='sHTKI'><ins id='sHTKI'></ins><ul id='sHTKI'></ul><sub id='sHTKI'></sub></form><legend id='sHTKI'></legend><bdo id='sHTKI'><pre id='sHTKI'><center id='sHTKI'></center></pre></bdo></b><th id='sHTKI'></th></span></q></dt></tr></i><div id='sHTKI'><tfoot id='sHTKI'></tfoot><dl id='sHTKI'><fieldset id='sHTKI'></fieldset></dl></div>
              • <bdo id='sHTKI'></bdo><ul id='sHTKI'></ul>

                <tfoot id='sHTKI'></tfoot>

                    <tbody id='sHTKI'></tbody>
                • 本文介绍了如何使用另一个表中的 MAX 值重置 MySQL AutoIncrement?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道这行不通.我以各种形式尝试过,但每次都失败了.实现以下结果的最简单方法是什么?

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

                  ALTER TABLE XYZ AUTO_INCREMENT = (select max(ID) from ABC);
                  

                  这非常适合自动化项目.

                  This is great for automation projects.

                  SELECT @max := (max(ID)+1) from ABC;        -> This works!
                  select ID from ABC where ID = (@max-1);     -> This works!
                  ALTER TABLE XYZ AUTO_INCREMENT = (@max+1);  -> This fails :( Why?
                  

                  推荐答案

                  使用 准备语句:

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

                  这篇关于如何使用另一个表中的 MAX 值重置 MySQL AutoIncrement?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:自增唯一标识符 下一篇:Mysql - 将 auto_increment 添加到主键

                  相关文章

                    <bdo id='zDfVl'></bdo><ul id='zDfVl'></ul>
                • <legend id='zDfVl'><style id='zDfVl'><dir id='zDfVl'><q id='zDfVl'></q></dir></style></legend>
                • <i id='zDfVl'><tr id='zDfVl'><dt id='zDfVl'><q id='zDfVl'><span id='zDfVl'><b id='zDfVl'><form id='zDfVl'><ins id='zDfVl'></ins><ul id='zDfVl'></ul><sub id='zDfVl'></sub></form><legend id='zDfVl'></legend><bdo id='zDfVl'><pre id='zDfVl'><center id='zDfVl'></center></pre></bdo></b><th id='zDfVl'></th></span></q></dt></tr></i><div id='zDfVl'><tfoot id='zDfVl'></tfoot><dl id='zDfVl'><fieldset id='zDfVl'></fieldset></dl></div>

                  1. <tfoot id='zDfVl'></tfoot>
                    1. <small id='zDfVl'></small><noframes id='zDfVl'>