我很開心測試了sql server 2012的columnstore索引功能。因爲您不能使用這樣的索引更新/插入表,所以我在一些選項上閱讀:保留一個單獨的表併爲每個批量插入使用新的分區或禁用索引,執行更新/插入,然後重建索引。存儲過程中的SQL Server列存儲索引更新/插入
對於我的測試,我選擇了後者選項,並結束了與此存儲過程:
-- Disable the columnstore index.
ALTER INDEX [All_Columns_Columnstore_Index] ON [dbo].[Tick] DISABLE
-- Insert data into tick table from staging table.
insert into Tick
select [Date],
SymbolID,
Price
from TickTemporary
-- Delete data from staging table.
delete from TickTemporary
-- Enable (rebuild) the columnstore index.
ALTER INDEX [All_Columns_Columnstore_Index] ON [dbo].[Tick] REBUILD
如果我執行這些行手動一切工作正常。但是,如果我運行該過程,則會出現更新/插入無法在具有列存儲索引的表上執行的錯誤。
這是爲什麼?
更新:
我跟着我以前接受答案的建議,但我仍然得到同樣的事情。
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Disable the columnstore index.
EXEC DisableColumnStoreIndex
-- Insert data into tick table from staging table.
insert into Tick
select [Date],
SymbolID,
Price
from TickTemporary
-- Delete data from staging table.
delete from TickTemporary
-- Enable (rebuild) the columnstore index.
EXEC RebuildColumnStoreIndex
即使試圖將「開始過渡」和「承諾過渡」周圍的存儲過程調用。
使用動態SQL這樣的:
declare @sql nvarchar(max)
set @sql =
'insert into Tick
select [Date],
SymbolID,
Price
from TickTemporary'
exec(@sql)
的作品,但說真的,我想不用動態sql度日。在這種情況下不可能嗎?
是。我計劃在未來使用該策略。但是現在這只是我的一個非常小的實驗,我沒有那麼多的數據。但是我已經閱讀過你提到的鏈接,所以我知道這種方法。當這個簡單的事情不起作用時,我就陷入了困境。 – UmaN
我不認爲你瞭解這個建議。你的嘗試stiull必須編譯一個存儲過程,插入一個列存儲索引,這將觸發錯誤。您必須將INSERT分離爲在列存儲索引存在時未編譯,因此非常簡單,並且沒有解決方法。動態SQL是一個強制編譯在正確的時間發生的例子。 –
對不起。我知道了。雖然我覺得奇怪的是,當你實際執行「CREATE PROCEDURE」或「ALTER PROCEDURE」語句時,沒有執行相同的檢查。但是,謝謝。 – UmaN