All pastes #17193 Raw Edit

||cw

public sql v1 · immutable
#17193 ·published 2005-07-07 22:25 UTC
rendered paste body
SET NOCOUNT ONDECLARE @tablename VARCHAR (128)DECLARE @execstr   VARCHAR (255)DECLARE indexes CURSOR FORSELECT 	sysobjects.nameFROM	sysobjects WHERE	sysobjects.name like 'tab_%'-- Open the cursorOPEN indexes-- loop through the indexesFETCH NEXT   FROM indexes   INTO @tablenameWHILE @@FETCH_STATUS = 0BEGIN   PRINT 'Executing DBCC DBREINDEX (''' + RTRIM(@tablename) + ''')' + char(10)   SELECT @execstr = 'DBCC DBREINDEX (''' + RTRIM(@tablename) + ''')'   EXEC (@execstr)   FETCH NEXT      FROM indexes      INTO @tablenameEND-- Close and deallocate the cursorCLOSE indexesDEALLOCATE indexes