Try this - create the SP in master database then run it against the databse you are interested in.
Hope it helps.
CREATE PROCEDURE dbo.sp_tablesize
@opcion AS Varchar(5)= false
AS
DECLARE @obj_id AS int
--declare @opcion as Varchar(5)--= false
--
DECLARE @strTabName SYSNAME
DECLARE @lngTabCount INTEGER
DECLARE @lngLoopCount INTEGER
IF @opcion IS NOT NULL
begin
SELECT @opcion = lower(@opcion)
IF @opcion NOT IN ('true','false')
begin
raiserror(15143,-1,-1,@opcion)
return(1)
END
end
IF (@opcion = 'true')
GOTO BaseDeDatos
IF (@opcion = 'false')
GOTO Tablas
BaseDeDatos:
EXEC sp_spaceused @updateusage = 'TRUE'
RETURN
Tablas:
SET nocount ON
CREATE TABLE #t
(
numID INTEGER IDENTITY(1,1)
,table_name SYSNAME
,[rows] varchar(25)
,reserved varchar(25)
,data varchar(25)
,index_size varchar(25)
,unused varchar(25)
)
CREATE TABLE #tTables
(
numID INTEGER IDENTITY(1,1)
,strTableName SYSNAME
)
INSERT INTO #tTables (strTableName)
SELECT name FROM dbo.sysobjects WHERE xtype = 'u' ORDER BY name DESC
SET @lngTabCount = @@ROWCOUNT
SET @lngLoopCount = @lngTabCount
WHILE @lngLoopCount <> 0
BEGIN
SET @strTabName = '[dbo].' + (SELECT strTableName FROM #tTables WHERE numID = @lngLoopCount)
--set @rows = (select count(*) FROM #tTa
-- bles WHERE numID = @lngLoopCount)
SELECT @obj_id = object_id(@strTabName)
INSERT INTO #t (table_name,[rows],reserved,data,index_size,unused)
EXEC sp_spaceused @strTabName
SET @lngLoopCount = @lngLoopCount - 1
END
DROP TABLE #tTables
SELECT * FROM #t
DROP TABLE #t
RETURN
GO
DBomrrsm