CREATE PROC USP_FRAGLIST
AS
BEGIN
CREATE TABLE #FRAGLIST (
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)
INSERT INTO #FRAGLIST
EXEC('DBCC SHOWCONTIG WITH TABLERESULTS')
DECLARE @INDEXNAME VARCHAR(50)
DECLARE C1 CURSOR FOR SELECT INDEXNAME FROM #FRAGLIST WHERE SCANDENSITY <=50 AND LTRIM(RTRIM(ISNULL(INDEXNAME,'')))<>''
OPEN C1
FETCH NEXT FROM C1 INTO @INDEXNAME
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@INDEXNAME)
FETCH NEXT FROM C1 INTO @INDEXNAME
END
CLOSE C1
DEALLOCATE C1
END
AS
BEGIN
CREATE TABLE #FRAGLIST (
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)
INSERT INTO #FRAGLIST
EXEC('DBCC SHOWCONTIG WITH TABLERESULTS')
DECLARE @INDEXNAME VARCHAR(50)
DECLARE C1 CURSOR FOR SELECT INDEXNAME FROM #FRAGLIST WHERE SCANDENSITY <=50 AND LTRIM(RTRIM(ISNULL(INDEXNAME,'')))<>''
OPEN C1
FETCH NEXT FROM C1 INTO @INDEXNAME
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@INDEXNAME)
FETCH NEXT FROM C1 INTO @INDEXNAME
END
CLOSE C1
DEALLOCATE C1
END
No comments:
Post a Comment