-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path090. SQL Server Script to check the Allocation Units of a Table
More file actions
57 lines (52 loc) · 1.93 KB
/
090. SQL Server Script to check the Allocation Units of a Table
File metadata and controls
57 lines (52 loc) · 1.93 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
--********* 090. SQL Server Script to check the Allocation Units of a Table
--Reference : https://www.sqlskills.com/
DECLARE @object SYSNAME = 'table_name'
SELECT
OBJECT_NAME ([sp].[object_id]) AS [Object Name],
[sp].[index_id] AS [Index ID],
[sp].[partition_id] AS [Partition ID],
[sa].[allocation_unit_id] AS [Alloc Unit ID],
[sa].[type_desc] AS [Alloc Unit Type],
'(' + CONVERT (VARCHAR (6),
CONVERT (INT,
SUBSTRING ([sa].[first_page], 6, 1) +
SUBSTRING ([sa].[first_page], 5, 1))) +
':' + CONVERT (VARCHAR (20),
CONVERT (INT,
SUBSTRING ([sa].[first_page], 4, 1) +
SUBSTRING ([sa].[first_page], 3, 1) +
SUBSTRING ([sa].[first_page], 2, 1) +
SUBSTRING ([sa].[first_page], 1, 1))) +
')' AS [First Page],
'(' + CONVERT (VARCHAR (6),
CONVERT (INT,
SUBSTRING ([sa].[root_page], 6, 1) +
SUBSTRING ([sa].[root_page], 5, 1))) +
':' + CONVERT (VARCHAR (20),
CONVERT (INT,
SUBSTRING ([sa].[root_page], 4, 1) +
SUBSTRING ([sa].[root_page], 3, 1) +
SUBSTRING ([sa].[root_page], 2, 1) +
SUBSTRING ([sa].[root_page], 1, 1))) +
')' AS [Root Page],
'(' + CONVERT (VARCHAR (6),
CONVERT (INT,
SUBSTRING ([sa].[first_iam_page], 6, 1) +
SUBSTRING ([sa].[first_iam_page], 5, 1))) +
':' + CONVERT (VARCHAR (20),
CONVERT (INT,
SUBSTRING ([sa].[first_iam_page], 4, 1) +
SUBSTRING ([sa].[first_iam_page], 3, 1) +
SUBSTRING ([sa].[first_iam_page], 2, 1) +
SUBSTRING ([sa].[first_iam_page], 1, 1))) +
')' AS [First IAM Page]
FROM
sys.system_internals_allocation_units AS [sa],
sys.partitions AS [sp]
WHERE
[sa].[container_id] = [sp].[partition_id]
AND [sp].[object_id] =
(CASE WHEN (@object IS NULL)
THEN [sp].[object_id]
ELSE OBJECT_ID (@object)
END)