Sqlserver的表沒有高水位但是有碎片的概念,sqlserver表的碎片的檢視和整理方法
官方文件
1、雖然官方推薦使用sys.dm_db_index_physical_stats來代替DBCC SHOWCONTIG檢視碎片資訊,但是DBCC SHOWCONTIG顯示出來的結果還是更直觀些
2、如果表有聚集索引,表就是索引組織表,對錶進行碎片整理,使用ALTER INDEX ALL ON Table_Name REORGANIZE就行
3、如果表沒有聚集索引,表就是堆表,對錶進行碎片整理,如果ALTER INDEX ALL ON Table_Name REORGANIZE沒有達到效果,就再使用alter table table_name REBUILD WITH ( <rebuild_option> )
查詢wondb庫下dbo.RSMsi1的碎片資訊
方法1:使用DBCC SHOWCONTIG ,Avg. Page Density (full)越小,碎片越大
DBCC SHOWCONTIG ('wondb.dbo.RSMsi1'); DBCC SHOWCONTIG scanning 'RsmSi1' table... Table: 'RsmSi1' (1419152101); index ID: 1, database ID: 24 TABLE level scan performed. - Pages Scanned................................: 3728 - Extents Scanned..............................: 452 - Extent Switches..............................: 351 - Avg. Pages per Extent........................: 7.8 - Scan Density [Best Count:Actual Count].......: 98.41% [248:252] - Logical Scan Fragmentation ..................: 0.40% - Extent Scan Fragmentation ...................: 4.37% - Avg. Bytes Free per Page.....................: 800.4 - Avg. Page Density (full).....................: 60.11% DBCC execution completed. If DBCC printed error messages, contact your system administrator.
方法2:使用sys.dm_db_index_physical_stats
use wondb;--以下語句需要在當前資料庫下執行 select index_type_desc,avg_fragment_size_in_pages,page_count,avg_fragmentation_in_percent from sys.dm_db_index_physical_stats (db_id(), object_id ('RSMsi1'), default, default, default) index_type_desc avg_fragment_size_in_pages page_count avg_fragmentation_in_percent CLUSTERED INDEX 164.833333333333 3728 0.404448938321537 NONCLUSTERED INDEX 159.818181818182 3721 0.341296928327645
整理wondb庫下dbo.RSMsi1的碎片
方法1:重新組織索引而非重建索引,REORGANIZE重新組織索引不會引發堵塞,再收集統計資訊
USE WONDB;
GO
ALTER INDEX ALL ON [dbo].[RSMsi1] REORGANIZE ;
GO
UPDATE STATISTICS [dbo].[RSMsi1];
GO
再檢視碎片資訊
DBCC SHOWCONTIG (RSMsi1);
DBCC SHOWCONTIG scanning 'RsmSi1' table... Table: 'RsmSi1' (1419152101); index ID: 1, database ID: 24 TABLE level scan performed. - Pages Scanned................................: 1978 - Extents Scanned..............................: 249 - Extent Switches..............................: 248 - Avg. Pages per Extent........................: 7.9 - Scan Density [Best Count:Actual Count].......: 99.60% [248:249] - Logical Scan Fragmentation ..................: 0.35% - Extent Scan Fragmentation ...................: 6.83% - Avg. Bytes Free per Page.....................: 800.4 - Avg. Page Density (full).....................: 90.11% DBCC execution completed. If DBCC printed error messages, contact your system administrator.
select index_type_desc,avg_fragment_size_in_pages,page_count,avg_fragmentation_in_percent from sys.dm_db_index_physical_stats (db_id(), object_id ('RSMsi1'), default, default, default)
index_type_desc avg_fragment_size_in_pages page_count avg_fragmentation_in_percent CLUSTERED INDEX 104.105263157895 1978 0.353892821031345 NONCLUSTERED INDEX 103.411764705882 1758 0.341296928327645
方法2:再對錶執行rebuild操作
alter table RSMsi1 rebuild with (>
REBUILD WITH ( <rebuild_option> )
如果表具有聚集索引,則 REBUILD 選項將重新生成該聚集索引。 REBUILD 可以為 ONLINE 操作。
如果表沒有聚集索引,堆結構只受部分選項影響。
再檢視碎片資訊
DBCC SHOWCONTIG (RSMsi1);
DBCC SHOWCONTIG scanning 'RsmSi1' table... Table: 'RsmSi1' (1419152101); index ID: 1, database ID: 24 TABLE level scan performed. - Pages Scanned................................: 1978 - Extents Scanned..............................: 252 - Extent Switches..............................: 251 - Avg. Pages per Extent........................: 7.8 - Scan Density [Best Count:Actual Count].......: 98.41% [248:252] - Logical Scan Fragmentation ..................: 0.40% - Extent Scan Fragmentation ...................: 4.37% - Avg. Bytes Free per Page.....................: 800.4 - Avg. Page Density (full).....................: 90.11% DBCC execution completed. If DBCC printed error messages, contact your system administrator.
select index_type_desc,avg_fragment_size_in_pages,page_count,avg_fragmentation_in_percent from sys.dm_db_index_physical_stats (db_id(), object_id ('RSMsi'), default, default, default)
index_type_desc avg_fragment_size_in_pages page_count avg_fragmentation_in_percent CLUSTERED INDEX 164.833333333333 1978 0.404448938321537 NONCLUSTERED INDEX 103.411764705882 1758 0.341296928327645
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30126024/viewspace-2745081/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL表碎片整理MySql
- Oracle資料表碎片整理Oracle
- MySQL的表碎片處理MySql
- mssql sqlserver 快速表備份和表還原的方法SQLServer
- Oracle資料庫表碎片整理Oracle資料庫
- Oracle 資料庫整理表碎片Oracle資料庫
- SQLServer插入資料到有自增列的表SQLServer
- SQLServer臨時表的使用SQLServer
- 檢視sqlserver的某程式的sql文字SQLServer
- Sqlserver 如何truncate linked server的表SQLServer
- Sqlserver 關於臨時表和表變數的總結SQLServer變數
- 索引碎片整理索引
- Sqlserver表和索引壓縮SQLServer索引
- SQLServer的檢查點、redo和undoSQLServer
- SqlServer關於分割槽表的總結SQLServer
- SQLServer中Tab製表符的影響SQLServer
- win10系統無法整理磁碟碎片提示已由其它程式建立了計劃磁碟碎片整理的解決方法Win10
- (2) SqlServer表與索引的結構的補充SQLServer索引
- 檢視SQLServer的LCK資源等待情況SQLServer
- mssql sqlserver 表增加列後,檢視不會自動更新相關列的兩種解決方法分享SQLServer
- Mysql 大資料表 資料匯入到SqlServer 中的方法MySql大資料Server
- SQLSERVER 臨時表和表變數到底有什麼區別?SQLServer變數
- 硬碟加速和磁碟碎片整理軟體硬碟
- (1)掌握SqlServer索引的基本概念SQLServer索引
- ORACLE常見檢視和表整理Oracle
- SQLSERVER 的 truncate 和 delete 有區別嗎?SQLServerdelete
- sqlserver鎖表的六種語法及with nolock的說明SQLServer
- DataX的知識碎片
- win10怎麼禁用磁碟整理_win10關閉磁碟碎片整理的方法Win10
- 檢視錶和索引碎片情況相關資訊索引
- 檢視SQLSERVER主鍵列SQLServer
- mysql之 OPTIMIZE TABLE整理碎片MySql
- java/android 做題中整理的碎片小貼士(4)JavaAndroid
- 表碎片起因及解決辦法(zt)
- SQLServer進行表歸檔SQLServer
- Spark Core的知識碎片Spark
- 檢視錶名和表的行數
- sqlserver的坑SQLServer