代码之家  ›  专栏  ›  技术社区  ›  Keith Nicholas

如何从另一个表架构创建空的临时表?

  •  7
  • Keith Nicholas  · 技术社区  · 15 年前

    有没有一种惯用的方法来做到这一点?

    3 回复  |  直到 9 年前
        1
  •  25
  •   Michael Buen    15 年前
    select * into x_temp from tbl where 1 = 0
    
        2
  •  2
  •   Hamid Pourjam    10 年前

    这适用于大多数DBS:

    create table blah as
    select * from foo where 1=0
    

    请注意,这不会复制pk、索引等。

        3
  •  1
  •   Andrew V    9 年前
    select top 0 * into temp_table from table
    

    这是我通常使用的方法,但我也喜欢迈克尔B的方法。