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

  • <small id='BezNf'></small><noframes id='BezNf'>

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

      <tfoot id='BezNf'></tfoot>
      1. <legend id='BezNf'><style id='BezNf'><dir id='BezNf'><q id='BezNf'></q></dir></style></legend>

        ALTER TABLE my_table ADD @column INT

        ALTER TABLE my_table ADD @column INT(ALTER TABLE my_table ADD @column INT)
              <i id='aek2w'><tr id='aek2w'><dt id='aek2w'><q id='aek2w'><span id='aek2w'><b id='aek2w'><form id='aek2w'><ins id='aek2w'></ins><ul id='aek2w'></ul><sub id='aek2w'></sub></form><legend id='aek2w'></legend><bdo id='aek2w'><pre id='aek2w'><center id='aek2w'></center></pre></bdo></b><th id='aek2w'></th></span></q></dt></tr></i><div id='aek2w'><tfoot id='aek2w'></tfoot><dl id='aek2w'><fieldset id='aek2w'></fieldset></dl></div>
                <bdo id='aek2w'></bdo><ul id='aek2w'></ul>
                  <legend id='aek2w'><style id='aek2w'><dir id='aek2w'><q id='aek2w'></q></dir></style></legend>

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

                  <tfoot id='aek2w'></tfoot>

                    <tbody id='aek2w'></tbody>

                  本文介绍了ALTER TABLE my_table ADD @column INT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我想使用一个变量作为新列的名称,这在 MS SQL 中可行吗?

                  If i want to use a variable as name of the new column, is this posible in MS SQL?

                  不起作用的例子:

                  ALTER TABLE my_table ADD @column INT
                  

                  这对我很有用:

                  EXEC ('ALTER TABLE my_table ADD ' + @column + ' INT')
                  

                  推荐答案

                  这可以使用动态 sql 构建您的 DDL 并使用 EXEC 命令执行字符串.

                  This is possible using dynamic sql to build your DDL and using the EXEC command to execute the string.

                  Declare @SQL VarChar(1000)
                  
                  SELECT @SQL = 'ALTER TABLE my_table ADD ' + @column + ' INT'
                  
                  Exec (@SQL)
                  

                  请参阅这篇文章.

                  我还要补充一点,当您冒险进入动态 sql 领域时,您需要注意不要将自己暴露在 SQL 注入攻击.总是清理传入的参数.

                  I will also add that the moment you venture to the land of dynamic sql, you need to take care to not expose yourself to SQL Injection attacks. Always clean up the parameters coming in.

                  正如 Philip 所提到的 - 在执行此操作之前要深思熟虑.可能的事实并不使它成为一件好事...

                  As Philip mentions - think long and hard before doing this. The fact that it is possible does not make it a good thing...

                  Erland Sommarskog 写了一篇关于使用动态 SQL 的详尽文章 - 动态 SQL 的诅咒与祝福我建议阅读全文.

                  Erland Sommarskog wrote an extensive article about using dynamic sql - The curse and blessings of dynamic SQL which I recommend reading fully.

                  这篇关于ALTER TABLE my_table ADD @column INT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Python Pandas write to sql with NaN values(Python Pandas 使用 NaN 值写入 sql)
                  MySQL Insert amp; Joins(MySQL 插入 amp;加入)
                  MySQL concat() to create column names to be used in a query?(MySQL concat() 创建要在查询中使用的列名?)
                  NodeJS responded MySQL timezone is different when I fetch directly from MySQL(当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同)
                  WHERE datetime older than some time (eg. 15 minutes)(WHERE 日期时间早于某个时间(例如 15 分钟))
                  How to get a list of months between two dates in mysql(如何在mysql中获取两个日期之间的月份列表)
                    • <bdo id='SyNrl'></bdo><ul id='SyNrl'></ul>

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

                          1. <small id='SyNrl'></small><noframes id='SyNrl'>