Weird - the code (for rebuilding all indexed in a database) works in SQL Server 2005/2008/2008R2, but NOT in SQL Server 2012 - Update: now OK on 11.0.3401

--OK, it works in SQL Server 2012 too. I test it today on 11.0.3401.

USE AdventureWorks2012
GO

DECLARE tables_cursor CURSOR
FOR
SELECT s.NAME
     ,t.NAME
FROM sys.objects AS t
INNER JOIN sys.schemas AS s ON s.schema_id = t.schema_id
WHERE t.type = 'U';

OPEN tables_cursor;

DECLARE @schemaname SYSNAME;
DECLARE @tablename SYSNAME;

FETCH NEXT
FROM tables_cursor
INTO @schemaname
     ,@tablename

WHILE (@@FETCH_STATUS <> - 1)
BEGIN
     EXECUTE ('ALTER INDEX ALL ON ' + @schemaname + '.' + @tablename + ' Rebuild')

     FETCH NEXT
     FROM tables_cursor
     INTO @schemaname
           ,@tablename;
END

PRINT 'The indexes on all tables have been rebuilt.';

CLOSE tables_cursor;

DEALLOCATE tables_cursor;