Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 索引重新组织导致表';s索引以禁用其页面级锁定?_Sql Server - Fatal编程技术网

Sql server 索引重新组织导致表';s索引以禁用其页面级锁定?

Sql server 索引重新组织导致表';s索引以禁用其页面级锁定?,sql-server,Sql Server,我有一个奇怪的经历,在以前成功的存储过程中,它执行了以下操作:- ALTER INDEX ALL ON Prices_Staging REBUILD; TRUNCATE TABLE Prices_Empty; ALTER TABLE Prices switch TO Prices_Empty; ALTER TABLE Prices_Staging switch TO Prices; 这在过去一直有效,但“alterindex-ALL-ON-dbo.Prices_;”声明及时,碎

我有一个奇怪的经历,在以前成功的存储过程中,它执行了以下操作:-

ALTER INDEX ALL ON Prices_Staging REBUILD;  
TRUNCATE TABLE Prices_Empty;  
ALTER TABLE Prices switch TO Prices_Empty;  
ALTER TABLE Prices_Staging switch TO Prices;  
这在过去一直有效,但“alterindex-ALL-ON-dbo.Prices_;”声明及时,碎片仅为0.3%

我在sp中引入了一个测试来检查表索引的平均碎片

SET @Frag = (SELECT 
sum(avg_fragmentation_in_percent)
FROM sys.dm_db_index_physical_stats
    (
DB_ID(@DATABASE)
,OBJECT_ID(@TableName)
,OBJECT_ID(@IndexName)
,NULL
,NULL
))

If @Frag > 30
BEGIN

ALTER INDEX ALL ON Prices_Staging REBUILD;     

END
ELSE
BEGIN

ALTER INDEX ALL ON Prices_Staging SET(ALLOW_PAGE_LOCKS = ON);       
ALTER INDEX ALL ON Prices_Staging REORGANIZE;

END

Now, the final SWITCH fails as it reports that the indexes are not the same between staging and prices ?
进一步的调查显示,表上的所有索引都禁用了页面级锁定

我可以通过重建表上的所有索引来解决这个问题

那么是什么导致重组禁用页面级锁定呢