SQL Server 2000 です。
declare @iCount int declare @iRowCount int declare @tablename varchar(30) declare @sql varchar(500) declare DB_cur2 insensitive cursor for SELECT name from dbo.sysobjects where xtype = 'U' open DB_cur2 select @iCount = 0 select @iRowCount = @@cursor_rows while(@iCount < @iRowCount) begin fetch next from DB_cur2 into @tablename select @sql = 'DBCC DBREINDEX (''' + @tablename + ''','''')' print @sql exec (@sql) select @iCount = @iCount + 1 END CLOSE DB_cur2 DEALLOCATE DB_cur2