Этот скрипт не включает имена схем, но получает большую часть информации, которую вы хотите для текущей базы данных. Я уверен, что вы можете адаптировать его к хранимой процедуре.
SET NOCOUNT ON
GO
DECLARE @tblSpaceUsed TABLE
(
[name] sysname NOT NULL,
[rows] int NOT NULL,
[reserved] nvarchar(50) NOT NULL,
[reservedKB] int NULL,
[data] nvarchar(50) NOT NULL,
[dataKB] int NULL,
[index] nvarchar(50) NOT NULL,
[indexKB] int NULL,
[unused] nvarchar(50) NOT NULL,
[unusedKB] int NULL
)
DECLARE @tableName sysname
DECLARE @tableNames CURSOR
SET @tableNames = CURSOR
FAST_FORWARD
FOR
SELECT DISTINCT
ss.name + '.' + st.name
FROM
sys.tables st
INNER JOIN
sys.schemas ss
ON st.schema_id = ss.schema_id
OPEN @tableNames
FETCH NEXT FROM @tableNames INTO @tableName
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO @tblSpaceUsed ([name], [rows], [reserved], [data], [index], [unused]) EXEC sp_spaceused @tableName
FETCH NEXT FROM @tableNames INTO @tableName
END
CLOSE @tableNames
UPDATE
@tblSpaceUsed
SET
[reservedKB] = CONVERT(int, LEFT([reserved], LEN([reserved]) - 3)),
[dataKB] = CONVERT(int, LEFT([data], LEN([data]) - 3)),
[indexKB] = CONVERT(int, LEFT([index], LEN([index]) - 3)),
[unusedKB] = CONVERT(int, LEFT([unused], LEN([unused]) - 3))
SELECT
*
FROM
@tblSpaceUsed