1
clic en el botón " Inicio" de Windows y seleccione " Todos los programas". Haz click para ampliar Los Sims 2
Introduzca las siguientes sentencias SQL en la ventana de consola " Consola de administración de SQL . " :
SET NOCOUNT ON;
DECLARE @ nombre_tabla varchar ( 255 ) ;
DECLARE @ execstr varchar ( 400 ) ;
DECLARE @ objectid int ;
DECLARE @ indexid int ;
DECLARE @ frag decimal ;
DECLARE @ MaxFrag decimal;
SELECT @ MaxFrag = 30,0 ; ' . '
DECLARE CURSOR PARA tablas
SELECT TABLE_SCHEMA + + TABLE_NAME
DE INFORMATION_SCHEMA.TABLES
DONDE TABLE_TYPE = ' BASE TABLE' ;
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 ,
Extensión int ,
ExtentSwitches int ,
AvgFreeBytes int ,
AvgPageDensity int ,
ScanDensity decimal,
BestCount int ,
< p> ActualCount int ,
decimal LogicalFrag ,
ExtentFrag decimal) ;
mesas abiertas ;
TRAER DESPUÉS
DE tablas
EN @ nombre_tabla ;
MIENTRAS @ @ FETCH_STATUS = 0
COMENZAR
INSERT INTO # fraglist
EXEC ( ' DBCC SHOWCONTIG ( '' ' + @ nombre de tabla + ''' )
CON RÁPIDA , TABLERESULTS , ALL_INDEXES , NO_INFOMSGS ');
TRAER DESPUÉS
DE tablas
EN @ nombre_tabla ;
END;
mesas cerca
;
DEALLOCATE tablas ;
índices DECLARE CURSOR PARA SELECCIONAR
ObjectName , ObjectId , IndexId , LogicalFrag
desde # fraglist
DONDE LogicalFrag > = @ MaxFrag
Y INDEXPROPERTY ( ObjectId , IndexName , ' IndexDepth ' ) > 0 ;
índices abiertos ;
TRAER DESPUÉS DE
índices
EN @ nombre de tabla , @ objectid , indexid @ , @ frag ;
MIENTRAS @ @ FETCH_STATUS = 0
COMENZAR
PRINT ' Ejecutar DBCC INDEXDEFRAG ( 0 , ' + RTRIM (@ nombre de tabla ) + ',
' + RTRIM (@ indexid ) + ' ) - la fragmentación actualmente '
RTRIM ( CONVERT ( varchar ( 15 ) , @ frag )) + '% ' ;
SELECT @ execstr =' DBCC INDEXDEFRAG ( 0 , '+ RTRIM (@ objectid ) + ',
' + RTRIM (@ indexid ) + ' )';
EXEC (@ execstr ) ;
TRAER DESPUÉS DE
índices
EN @ nombre de tabla , @ objectid , indexid @ , @ frag ;
END;
índices CERRAR
;
DEALLOCATE índices ;
< p > TABLE DROP # fraglist ; .
GO
3
Haga clic en " archivo" y seleccione " Ejecutar" para desfragmentar el índice de base de datos MSSQL