日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sqlserver索引维护(重新组织生成索引)

發布時間:2023/12/19 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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_do

2:查看單表的索引碎片

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;

?

看一下官網的推薦:

?

avg_fragmentation_in_percent?值

修復語句

> 5% 且 < = 30%

ALTER INDEX REORGANIZE

> 30%

ALTER INDEX REBUILD WITH (ONLINE = ON)*

?

所以說大于百分三十的索引是要重建的. ---------------------------------------------重新組織索引---------------------------------------- ALTER INDEX IX_Employee_OrganizationalLevel_OrganizationalNode ON HumanResources.Employee REORGANIZE ; GO

?

--------------------------------------------重新組織表中所有的索引-------------------------------------------- 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索引维护(重新组织生成索引)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。