<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:如果列不存在,如何添加?

        MySQL: How to add a column if it doesn#39;t already exist?(MySQL:如果列不存在,如何添加?)

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

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                  MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)

                    • <bdo id='fJM7G'></bdo><ul id='fJM7G'></ul>
                    • <legend id='fJM7G'><style id='fJM7G'><dir id='fJM7G'><q id='fJM7G'></q></dir></style></legend>
                        • <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>
                            <tbody id='fJM7G'></tbody>