是否有性能或内存优势:Select A、B、C 从查询 VS Select 到临时(Select A、B、C 从 table)作为表

Is there a performance or memory benefit : Select A, B, C into temp from query VS Select into temp from (Select A,B,C from table) as TTable

在Sql服务器(2008版)中, 我有两个这样的查询:

Select * from sampleTable into #tempTable 

Select * into #tempTable from (Select Query) as someTableName

这些查询是否对性能或内存有 space 好处?或者两者都同样好。

这是众所周知的,他们单独比

Insert into Temp 
<Query>

但是相互比较又如何呢?

更新文本: 两个查询是这样的:

 Select A,B,C into #tempTable from TestTable

Select * into #tempTable from (Select A,B,C from TestTable) as someTableName

所有这些都会产生相同的查询计划。

SQL服务器有一个查询优化器,优化冗余列是最简单和最基本的优化。

自己回答此类问题的最佳方法是查看查询计划并进行比较。记住特定查询的性能行为通常毫无意义。这是了解一般如何优化和执行查询的更好方法。

性能相同

如果你打算使用像 10000 这样的非常大的数据集,那么 #temptable 会减慢查询速度,如果你使用它进行分页或有 groupby 的东西,并且在较新的版本中获取 newxt 行方法