<legend id='RqwIH'><style id='RqwIH'><dir id='RqwIH'><q id='RqwIH'></q></dir></style></legend>
  • <tfoot id='RqwIH'></tfoot>
      <bdo id='RqwIH'></bdo><ul id='RqwIH'></ul>

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

      1. 创建临时表前先检查临时表是否存在,如果存在则删除

        Check if a temporary table exists and delete if it exists before creating a temporary table(创建临时表前先检查临时表是否存在,如果存在则删除)
      2. <legend id='W20lO'><style id='W20lO'><dir id='W20lO'><q id='W20lO'></q></dir></style></legend>

        <tfoot id='W20lO'></tfoot>

              <bdo id='W20lO'></bdo><ul id='W20lO'></ul>
              1. <small id='W20lO'></small><noframes id='W20lO'>

                  <tbody id='W20lO'></tbody>
                <i id='W20lO'><tr id='W20lO'><dt id='W20lO'><q id='W20lO'><span id='W20lO'><b id='W20lO'><form id='W20lO'><ins id='W20lO'></ins><ul id='W20lO'></ul><sub id='W20lO'></sub></form><legend id='W20lO'></legend><bdo id='W20lO'><pre id='W20lO'><center id='W20lO'></center></pre></bdo></b><th id='W20lO'></th></span></q></dt></tr></i><div id='W20lO'><tfoot id='W20lO'></tfoot><dl id='W20lO'><fieldset id='W20lO'></fieldset></dl></div>
                • 本文介绍了创建临时表前先检查临时表是否存在,如果存在则删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用以下代码检查临时表是否存在并在再次创建之前删除该表是否存在.只要我不更改列,它就可以正常工作.如果我稍后添加一列,它会给出一个错误提示无效的列".请让我知道我做错了什么.

                  I am using the following code to check if the temporary table exists and drop the table if it exists before creating again. It works fine as long as I don't change the columns. If I add a column later, it will give an error saying "invalid column". Please let me know what I am doing wrong.

                  IF OBJECT_ID('tempdb..#Results') IS NOT NULL
                      DROP TABLE #Results
                  
                  CREATE TABLE #Results
                  (
                      Company                CHAR(3),
                      StepId                TINYINT,
                      FieldId                TINYINT,
                  )
                  
                  select company, stepid, fieldid from #Results
                  
                  --Works fine to this point
                  
                  IF OBJECT_ID('tempdb..#Results') IS NOT NULL
                      DROP TABLE #Results
                  
                  CREATE TABLE #Results
                  (
                      Company                CHAR(3),
                      StepId                TINYINT,
                      FieldId                TINYINT,
                      NewColumn            NVARCHAR(50)
                  )
                  
                  select company, stepid, fieldid, NewColumn from #Results
                  
                  --Does not work
                  

                  推荐答案

                  我无法重现该错误.

                  也许我不明白这个问题.

                  Perhaps I'm not understanding the problem.

                  以下在 SQL Server 2005 中对我来说很好用,额外的foo"列出现在第二个选择结果中:

                  The following works fine for me in SQL Server 2005, with the extra "foo" column appearing in the second select result:

                  IF OBJECT_ID('tempdb..#Results') IS NOT NULL DROP TABLE #Results
                  GO
                  CREATE TABLE #Results ( Company CHAR(3), StepId TINYINT, FieldId TINYINT )
                  GO
                  select company, stepid, fieldid from #Results
                  GO
                  ALTER TABLE #Results ADD foo VARCHAR(50) NULL
                  GO
                  select company, stepid, fieldid, foo from #Results
                  GO
                  IF OBJECT_ID('tempdb..#Results') IS NOT NULL DROP TABLE #Results
                  GO
                  

                  这篇关于创建临时表前先检查临时表是否存在,如果存在则删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  SQL Server add auto increment primary key to existing table(SQL Server 向现有表添加自动增量主键)
                  Altering a column: null to not null(改变列:null 到 not null)
                  Adding an identity to an existing column(向现有列添加标识)
                  How to write UPDATE SQL with Table alias in SQL Server 2008?(如何在 SQL Server 2008 中使用表别名编写 UPDATE SQL?)
                  Why can#39;t I use alias in a count(*) quot;columnquot; and reference it in a having clause?(为什么我不能在计数(*)“列中使用别名?并在具有条款中引用它?)
                  SQL Server 2005 quot;publicquot; database role doesn#39;t seem to apply?(SQL Server 2005“公共数据库角色似乎不适用?)
                  • <i id='Uqwny'><tr id='Uqwny'><dt id='Uqwny'><q id='Uqwny'><span id='Uqwny'><b id='Uqwny'><form id='Uqwny'><ins id='Uqwny'></ins><ul id='Uqwny'></ul><sub id='Uqwny'></sub></form><legend id='Uqwny'></legend><bdo id='Uqwny'><pre id='Uqwny'><center id='Uqwny'></center></pre></bdo></b><th id='Uqwny'></th></span></q></dt></tr></i><div id='Uqwny'><tfoot id='Uqwny'></tfoot><dl id='Uqwny'><fieldset id='Uqwny'></fieldset></dl></div>

                      <tbody id='Uqwny'></tbody>
                  • <small id='Uqwny'></small><noframes id='Uqwny'>

                    <legend id='Uqwny'><style id='Uqwny'><dir id='Uqwny'><q id='Uqwny'></q></dir></style></legend>
                    • <bdo id='Uqwny'></bdo><ul id='Uqwny'></ul>

                            <tfoot id='Uqwny'></tfoot>