我很开心测试了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