forked from ktaranov/sqlserver-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjects_Size_In_Database.sql
More file actions
31 lines (29 loc) · 1.22 KB
/
Copy pathObjects_Size_In_Database.sql
File metadata and controls
31 lines (29 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
<documentation>
<summary>Count size in bytes veiws, triggers, procedures and function in database.</summary>
<returns>1 data set: RoutinType, SUM LENGTH of objects, SUM DATALENGTH.</returns>
<issues>No</issues>
<author>Cade Roux</author>
<created>2008-10-20</created>
<modified>2019-06-26 by Konstantin Taranov</modified>
<version>1.0</version>
<sourceLink>https://github.com/ktaranov/sqlserver-kit/blob/master/Scripts/Objects_Size_In_Database.sql</sourceLink>
<originalLink>https://stackoverflow.com/a/219740/2298061</originalLink>
</documentation>
*/
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
WITH CTE_Routine AS (
/* Can not use INFORMATION_SCHEMA.ROUTINES because of 4000 character limit */
SELECT o.type_desc AS RoutineType
, o.[name] AS RoutineName
, m.[definition] AS RoutineDefinition
FROM sys.sql_modules AS m
INNER JOIN sys.objects AS o ON m.object_id = o.object_id
)
SELECT RoutineType
, SUM(LEN(RoutineDefinition)) AS RoutineLen
/* DATALENGTH for counting trailing space in the end of objects definitions */
, SUM(DATALENGTH(RoutineDefinition)) / 2 AS RoutineDatalength
FROM CTE_Routine
GROUP BY RoutineType;