declare	@idx_nom		sysname,
		@table_nom		varchar(50),
		@schema			varchar(20),
		@cmd			varchar(200)


-- 
Declare cursor1 cursor scroll for
	select	i.name,
		t.name,
		s.table_schema
		from sys.indexes i , sys.tables t, INFORMATION_SCHEMA.TABLES s
		where	i.object_id=t.object_id and
				t.name= s.table_name	and 
				t.type='U'
		order  by t.name
open cursor1



fetch next from cursor1 into @idx_nom, @table_nom, @schema
while @@fetch_status = 0

    begin
	print '-------------------------------------------------'
	print @idx_nom
	print @table_nom

	set @cmd= 'DBCC INDEXDEFRAG (0,'''+@schema+'.'+@table_nom+''','+@idx_nom+')'
	print @cmd		

      --execute (@cmd)
	fetch next from cursor1 into @idx_nom, @table_nom, @schema
    end


close cursor1
deallocate cursor1
