-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtableSizesCommon.sql
More file actions
59 lines (55 loc) · 1.92 KB
/
tableSizesCommon.sql
File metadata and controls
59 lines (55 loc) · 1.92 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use bestDR14
go
---size of tables
SELECT SCH.name AS SchemaName
,OBJ.name AS ObjName
,OBJ.type_desc AS ObjType
,INDX.name AS IndexName
,INDX.type_desc AS IndexType
,PART.partition_number AS PartitionNumber
,PART.rows AS PartitionRows
,STAT.row_count AS StatRowCount
,STAT.used_page_count * 8 AS UsedSizeKB
,STAT.reserved_page_count * 8 AS RevervedSizeKB
,drx.common
FROM sys.partitions AS PART
INNER JOIN sys.dm_db_partition_stats AS STAT
ON PART.partition_id = STAT.partition_id
AND PART.partition_number = STAT.partition_number
INNER JOIN sys.objects AS OBJ
ON STAT.object_id = OBJ.object_id
INNER JOIN sys.schemas AS SCH
ON OBJ.schema_id = SCH.schema_id
INNER JOIN sys.indexes AS INDX
ON STAT.object_id = INDX.object_id
AND STAT.index_id = INDX.index_id
join SueDB.dbo.DRxTables drx
on drx.tablename=OBJ.name
where OBJ.type_desc='USER_TABLE'
ORDER BY SCH.name
,OBJ.name
,INDX.name
,PART.partition_number
--sum of common / unique tables
SELECT
--OBJ.name AS ObjName
sum(STAT.used_page_count * 8) AS UsedSizeKB
,sum(STAT.reserved_page_count * 8) AS RevervedSizeKB
,sum((stat.reserved_page_count * 8) / 1000 /1000) as ReservedSizeGB
,drx.common
FROM sys.partitions AS PART
INNER JOIN sys.dm_db_partition_stats AS STAT
ON PART.partition_id = STAT.partition_id
AND PART.partition_number = STAT.partition_number
INNER JOIN sys.objects AS OBJ
ON STAT.object_id = OBJ.object_id
INNER JOIN sys.schemas AS SCH
ON OBJ.schema_id = SCH.schema_id
INNER JOIN sys.indexes AS INDX
ON STAT.object_id = INDX.object_id
AND STAT.index_id = INDX.index_id
join SueDB.dbo.DRxTables drx
on drx.tablename=OBJ.name
where OBJ.type_desc='USER_TABLE'
group by drx.common
sp_helpfile