How is possible to reindex a whole SQL Server database?

Version 1

    Sometimes is needed to reindex all the tables contained in a Microsoft SQL database.

    Run this script to achieve that result:

     

     declare @table_name sysname 
       declare table_reindexer CURSOR FOR 
       select table_name from information_schema.tables where table_type='BASE TABLE' 
       OPEN table_reindexer 
       FETCH NEXT FROM table_reindexer INTO @table_name 
       dbcc dbreindex(@table_name,'',0) 
       while @@fetch_status = 0 
       begin 
         FETCH NEXT FROM table_reindexer INTO @table_name 
         dbcc dbreindex(@table_name,'',0) 
       end 
       close table_reindexer 
       deallocate table_reindexer