Contents

1 碁煙 ク 磯ジ 碁煙 譟郁覈 ろ襴渚


1 碁煙 ク 磯ジ 碁煙 譟郁覈 ろ襴渚 #

Use 一危磯伎る -- 蠍一 碁煙 譟郁覈  碁煙 一危磯伎る .
GO

Create Table Rebuild_Index_Table(
   ObjectName CHAR (255),
   ObjectId INT,
   IndexName CHAR (255),
   IndexId INT,
   Lvl INT,
   CountPages INT,
   CountRows INT,
   MinRecSize INT,
   MaxRecSize INT,
   AvgRecSize INT,
   ForRecCount INT,
   Extents INT,
   ExtentSwitches INT,
   AvgFreeBytes INT,
   AvgPageDensity INT,
   ScanDensity DECIMAL,
   BestCount INT,
   ActualCount INT,
   LogicalFrag DECIMAL,
   ExtentFrag DECIMAL)
GO

INSERT INTO Rebuild_Index_Table
EXEC ('DBCC SHOWCONTIG WITH TABLERESULTS, ALL_INDEXES')
GO

--70% 危襦 譟郁 蟆
SELECT ObjectName, IndexName, CountPages,  
CAST(BestCount As Numeric) /  CAST(ActualCount As Numeric) * 100 'ScanDensity'
FROM Rebuild_Index_Table
WHERE CAST(BestCount As Numeric) /  CAST(ActualCount As Numeric) * 100 < 70
AND ObjectName NOT LIKE 'sys%'
AND ActualCount > 0
AND IndexName > ''

--碁煙  ろ襴渚
SELECT 'DBCC DBREINDEX ([' + CAST(RTRIM(ObjectName) AS VARCHAR(255)) + '],' + CAST(RTRIMIndexName) AS VARCHAR(255)) + ',' + '100)'
FROM Rebuild_Index_Table
WHERE CAST(BestCount As Numeric) /  CAST(ActualCount As Numeric) * 100 < 70
AND ObjectName NOT LIKE 'sys%'
AND ActualCount > 0
AND IndexName > ''

--碁煙 譟郁覈 ろ襴渚
SELECT 'DBCC INDEXDEFRAG(0,[' + CAST(RTRIM(ObjectName) AS VARCHAR(255)) + '],' + CASTRTRIM(IndexName) AS VARCHAR(255)) +')'
FROM Rebuild_Index_Table
WHERE CAST(BestCount As Numeric) /  CAST(ActualCount As Numeric) * 100 < 70
AND ObjectName NOT LIKE 'sys%'
AND ActualCount > 0
AND IndexName > ''

Drop table Rebuild_Index_Table
--碁煙 譟郁 覲企ゼ 覲願る Drop Table 讌 殊 .