IF OBJECT_ID(‚tempdb..#tblResults‘) IS NOT NULL DROP TABLE #tblResults
CREATE TABLE #tblResults
(
   [name]   nvarchar(255),
   [rows]   int,
   [reserved]   varchar(255),
   [reserved_int]   int default(0),
   [data]   varchar(255),
   [data_int]   int default(0),
   [index_size]   varchar(255),
   [index_size_int]   int default(0),
   [unused]   varchar(255),
   [unused_int]   int default(0)
)
EXEC sp_MSforeachtable @command1=
         „INSERT INTO #tblResults
           ([name],[rows],[reserved],[data],[index_size],[unused])
          EXEC sp_spaceused ‚?'“

SELECT * FROM #tblResults
Drop Table #tblResults

Advertisements