• <bdo id='n3lJC'></bdo><ul id='n3lJC'></ul>

    1. <i id='n3lJC'><tr id='n3lJC'><dt id='n3lJC'><q id='n3lJC'><span id='n3lJC'><b id='n3lJC'><form id='n3lJC'><ins id='n3lJC'></ins><ul id='n3lJC'></ul><sub id='n3lJC'></sub></form><legend id='n3lJC'></legend><bdo id='n3lJC'><pre id='n3lJC'><center id='n3lJC'></center></pre></bdo></b><th id='n3lJC'></th></span></q></dt></tr></i><div id='n3lJC'><tfoot id='n3lJC'></tfoot><dl id='n3lJC'><fieldset id='n3lJC'></fieldset></dl></div>
      <legend id='n3lJC'><style id='n3lJC'><dir id='n3lJC'><q id='n3lJC'></q></dir></style></legend>
    2. <tfoot id='n3lJC'></tfoot>
    3. <small id='n3lJC'></small><noframes id='n3lJC'>

        ALTER 表 - 在 MySQL 中添加 AUTOINCREMENT

        时间:2023-06-24
        • <bdo id='WXmTX'></bdo><ul id='WXmTX'></ul>

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

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

                <tfoot id='WXmTX'></tfoot>
                <legend id='WXmTX'><style id='WXmTX'><dir id='WXmTX'><q id='WXmTX'></q></dir></style></legend>

                  本文介绍了ALTER 表 - 在 MySQL 中添加 AUTOINCREMENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 MySQL 中用 itemID 列创建了一个表.

                  I created a table in MySQL with on column itemID.

                  创建表格后,现在我想将此列更改为AUTOINCREMENT.

                  After creating the table, now I want to change this column to AUTOINCREMENT.

                  如何使用 ALTER 语句完成此操作?

                  表定义:

                  ALLITEMS (itemid int(10) unsigned, itemname varchar(50))

                  我正在使用以下代码,但它引发了语法错误

                  I am using the following code but it is throwing a syntax error

                  错误:语法不正确.

                  ALTER TABLE allitems
                  MODIFY itemid INT(10) UNSIGNED AUTOINCREMENT; 
                  

                  推荐答案

                  CREATE TABLE ALLITEMS(
                      itemid INT(10)UNSIGNED,
                      itemname VARCHAR(50)
                  );
                  
                  ALTER TABLE ALLITEMS CHANGE itemid itemid INT(10)AUTO_INCREMENT PRIMARY KEY;
                  
                  DESC ALLITEMS;
                  
                  INSERT INTO ALLITEMS(itemname)
                  VALUES
                      ('Apple'),
                      ('Orange'),
                      ('Banana');
                  
                  SELECT
                      *
                  FROM
                      ALLITEMS;
                  

                  我之前也对 CHANGEMODIFY 关键字感到困惑:

                  I was confused with CHANGE and MODIFY keywords before too:

                  ALTER TABLE ALLITEMS CHANGE itemid itemid INT(10)AUTO_INCREMENT PRIMARY KEY;
                  
                  ALTER TABLE ALLITEMS MODIFY itemid INT(5);
                  

                  当我们在那里时,还要注意 AUTO_INCREMENT 也可以以预定义的数字开头:

                  While we are there, also note that AUTO_INCREMENT can also start with a predefined number:

                  ALTER TABLE tbl AUTO_INCREMENT = 100;
                  

                  这篇关于ALTER 表 - 在 MySQL 中添加 AUTOINCREMENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何更改 MySQL 列定义? 下一篇:在 sqlite3 中修改列的类型

                  相关文章

                  <tfoot id='SDN8B'></tfoot>

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

                    • <bdo id='SDN8B'></bdo><ul id='SDN8B'></ul>
                  1. <legend id='SDN8B'><style id='SDN8B'><dir id='SDN8B'><q id='SDN8B'></q></dir></style></legend>

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