Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I calculate the SIZE of stored procedures in SQL Server 2005?

I was asked for a comprehensive breakdown on space used within a specific database. I know I can use sys.dm_db_partition_stats in SQL Server 2005 to figure out how much space each table in a database is using, but is there any way to determine the individual and total size of the stored procedures in a database? (Short of opening each one and counting the characters, of course.)

Total space used by stored procs is not likely to be significant (compared to actual data), but with hundreds of them, it could add up.

like image 644
BradC Avatar asked Oct 20 '08 19:10

BradC


People also ask

How do I get the size of a SQL value?

SQL Server LEN() Function The LEN() function returns the length of a string. Note: Trailing spaces at the end of the string is not included when calculating the length.

How do I find the size of a SQL Server database?

If you need to check a single database, you can quickly find the SQL Server database sizein SQL Server Management Studio (SSMS): Right-click the database and then click Reports -> Standard Reports -> Disk Usage. Alternatively, you can use stored procedures like exec sp_spaceused to get database size.


1 Answers

;WITH ROUTINES AS (
    -- CANNOT use INFORMATION_SCHEMA.ROUTINES because of 4000 character limit
    SELECT o.type_desc AS ROUTINE_TYPE
            ,o.[name] AS ROUTINE_NAME
            ,m.definition AS ROUTINE_DEFINITION
    FROM sys.sql_modules AS m
    INNER JOIN sys.objects AS o
        ON m.object_id = o.object_id
)
SELECT SUM(LEN(ROUTINE_DEFINITION))
FROM ROUTINES
like image 116
Cade Roux Avatar answered Sep 28 '22 19:09

Cade Roux