• I'd suggest changing the order by on the last select to

    order by ISCLUSTERED desc, tablename, indexid, indexname

    This will insure the clustered indexes are created first, which you'll want to do if you ever run this for real.