<legend id='sbHDs'><style id='sbHDs'><dir id='sbHDs'><q id='sbHDs'></q></dir></style></legend>

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

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

      1. <tfoot id='sbHDs'></tfoot>
      2. <small id='sbHDs'></small><noframes id='sbHDs'>

      3. MySQL:如果列不存在,如何添加?

        时间:2023-06-24

          <tbody id='VajCV'></tbody>

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

                  本文介绍了MySQL:如果列不存在,如何添加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想向表中添加一列,但如果它已经添加到表中,我不希望它失败.我怎样才能做到这一点?

                  I want to add a column to a table, but I don't want it to fail if it has already been added to the table. How can I achieve this?

                  # Add column fails if it already exists 
                  ALTER TABLE `TableName` ADD `ColumnName` int(1) NOT NULL default '0';
                  

                  推荐答案

                  在存储过程中使用以下内容:

                  Use the following in a stored procedure:

                  IF NOT EXISTS( SELECT NULL
                              FROM INFORMATION_SCHEMA.COLUMNS
                             WHERE table_name = 'tablename'
                               AND table_schema = 'db_name'
                               AND column_name = 'columnname')  THEN
                  
                    ALTER TABLE `TableName` ADD `ColumnName` int(1) NOT NULL default '0';
                  
                  END IF;
                  

                  参考:

                  • INFORMATION_SCHEMA COLUMNS 表

                  这篇关于MySQL:如果列不存在,如何添加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如果存在则更改表或如果不存在则创建 下一篇:ALTER TABLE my_table ADD @column INT

                  相关文章

                  • <bdo id='fJM7G'></bdo><ul id='fJM7G'></ul>
                1. <legend id='fJM7G'><style id='fJM7G'><dir id='fJM7G'><q id='fJM7G'></q></dir></style></legend>
                  1. <small id='fJM7G'></small><noframes id='fJM7G'>

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