sqlserver索引维护(重新组织生成索引)
生活随笔
收集整理的這篇文章主要介紹了
sqlserver索引维护(重新组织生成索引)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
sqlserver索引的維護
1:查看索引碎片大于百分三十以上的索引
select object_id= object_id,indexid = index_id,partitionnum = partition_number,frag= avg_fragmentation_in_percent into #work_to_do from sys.dm_db_index_physical_stats(db_id(), null, null , null, 'LIMITED') --dm_ph_stats join sys.dm_db_partition_stats dm_pa_st on dm_ph_stats.object_id=dm_pa_st.object_id where avg_fragmentation_in_percent >= 30.0 and index_id > 0 and object_id in (select distinct a.object_id from sys.dm_db_partition_stats a join sys.indexes b on a.object_id=b.object_id and a.index_id=b.index_id where a.index_id>0 and a.in_row_data_page_count>1280 )select a.object_id,a.name,a.type_desc,b.partitionnum ,b.frag,b.indexid from sys.indexes a , #work_to_do b where a.object_id=b.object_id and a.index_id=b.indexid-- where object_id in(select objectid from #work_to_do) --drop table #work_to_do2:查看單表的索引碎片
SELECT a.index_id, name, avg_fragmentation_in_percent FROM sys.dm_db_index_physical_stats (DB_ID(N'MIAO'), OBJECT_ID(N'miao.注冊信息表'), NULL, NULL, NULL) AS a JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id;?
看一下官網的推薦:
?
| > 5% 且 < = 30% | ALTER INDEX REORGANIZE |
| > 30% | ALTER INDEX REBUILD WITH (ONLINE = ON)* ? |
?
--------------------------------------------重新組織表中所有的索引-------------------------------------------- ALTER INDEX ALL ON HumanResources.Employee REORGANIZE?
-------------------------------------------重新生成的索引-------------------------------------------- ALTER INDEX PK_Employee_BusinessEntityID ON HumanResources.Employee REBUILD; GO?
---------------------------------------------重新生成表中所有的索引-------------------------------------------- ALTER INDEX ALL ON Production.Product REBUILD WITH (FILLFACTOR = 80, SORT_IN_TEMPDB = ON,STATISTICS_NORECOMPUTE = ON);?
?
轉載于:https://www.cnblogs.com/shengdimaya/p/5341093.html
總結
以上是生活随笔為你收集整理的sqlserver索引维护(重新组织生成索引)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 职责链模式应用——下机(机房重构知识点总
- 下一篇: 大班音乐教案《拾豆豆》反思