<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?

        How can I reset an MySQL AutoIncrement using a MAX value from another table?(如何使用另一个表中的 MAX 值重置 MySQL AutoIncrement?)

      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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Select n random rows from SQL Server table(从 SQL Server 表中随机选择 n 行)
                  SQL query to select dates between two dates(用于选择两个日期之间的日期的 SQL 查询)
                  How can I delete using INNER JOIN with SQL Server?(如何在 SQL Server 中使用 INNER JOIN 进行删除?)
                  Table Naming Dilemma: Singular vs. Plural Names(表命名困境:单数与复数名称)
                  INSERT statement conflicted with the FOREIGN KEY constraint - SQL Server(INSERT 语句与 FOREIGN KEY 约束冲突 - SQL Server)
                  How ROWNUM works in pagination query?(ROWNUM 如何在分页查询中工作?)
                    <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>

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