使用显式创建表语句和加载数据与选择到数据库之间有任何性能差异。这个例子只显示了2列,但问题是适用于使用非常大的表格。下面的例子也使用临时表,但我想知道使用常规表的效果。尽管如此,我认为它们会是相同的。使用显式创建表语句创建表与选择到
临时表的场景:
--- Explicitly creating temp table first and then loading.
create table #test1 (id int, name varchar(100))
insert into #test1 (id, name) select id, name from #bigTable
--- Creating temp table by selecting into.
select id,name into #test2 from #bigTable
或常规表:
--- Explicitly creating table first and then loading.
create table test1 (id int, name varchar(100))
insert into test1 (id, name) select id, name from #bigTable
--- Creating table by selecting into.
select id,name into test2 from bigTable
什么是大家对这个想法?我认为明确创建表和加载必须比select into into更好的性能必须评估语句中的表达式才能创建表。
我们的组织通常会明确创建临时表作为标准做法,我们想知道什么都认为实际上是最佳实践。
http://msdn.microsoft.com/en-us/library/ms188029.aspx
我没有时间检查,但您可能会发现这是重新编译的原因。这个潜在的开销是否大于Adam Houldsworth所暗示的其他好处,我会留给你或其他人去找出:) – MatBailie
你检查过两种变种的执行计划吗?你是否真的计时了他们,看看有没有可衡量的差异? – HLGEM
我已经尝试了两个更早,但不是在一大组数据。我现在没有试图解决任何性能问题,我很好奇每种插入方法的优缺点... – mservidio