【问题标题】:Dropping indexes of global temp table in SQL Server [duplicate]在 SQL Server 中删除全局临时表的索引 [重复]
【发布时间】:2012-10-17 02:49:26
【问题描述】:

可能重复:
TSQL: Are indexes on temporary tables deleted when the table is deleted?

如何在 SQL Server 中手动删除全局临时表的索引?

编辑:如果您手动删除表格,您甚至需要这样做吗?

【问题讨论】:

    标签: sql sql-server temp-tables


    【解决方案1】:

    如果要删除临时表本身,则不需要删除临时表上的索引。它会在您删除表格时自动发生。

    Are indexes on temporary tables deleted when the table is deleted?

    【讨论】:

      【解决方案2】:

      当引用该表的所有会话都将结束时,或者当您手动删除该表时,全局临时表将连同其索引一起销毁,但是,如果需要,您仍然可以手动删除索引。

      语法是

      drop index ##MyTempTable.MyIndex
      

      或:

      drop index MyIndex on ##MyTempTable
      

      【讨论】:

        【解决方案3】:

        这对我创建然后删除索引很有用。

        CREATE TABLE ##TempTable (Col1 int)
        
        CREATE INDEX IDX on ##TempTable
        (Col1)
        
        DROP INDEX IDX ON ##TempTable
        

        【讨论】:

          猜你喜欢
          • 2010-10-15
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-11-19
          • 2011-12-17
          • 1970-01-01
          • 2014-09-01
          • 2012-02-13
          相关资源
          最近更新 更多