使用顯式創建表語句和加載數據與選擇到數據庫之間有任何性能差異。這個例子只顯示了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