You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: "Display data & log space info for a database"
3
3
description: Learn how to display the data and log space information for a database in SQL Server by using SQL Server Management Studio or Transact-SQL.
# Display Data and Log Space Information for a Database
25
+
# Display data and log space information for a database
26
26
[!INCLUDE[SQL Server Azure SQL Database Synapse Analytics PDW ](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)]
27
-
This topic describes how to display the data and log space information for a database in [!INCLUDE[ssCurrent](../../includes/sscurrent-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
27
+
This article describes how to display the data and log space information for a database in [!INCLUDE[ssCurrent](../../includes/sscurrent-md.md)] by using [!INCLUDE[ssManStudioFull](../../includes/ssmanstudiofull-md.md)] or [!INCLUDE[tsql](../../includes/tsql-md.md)].
28
28
29
29
30
-
## <aname="BeforeYouBegin"></a> Before You Begin
30
+
## <aname="BeforeYouBegin"></a> Before you begin
31
31
32
-
### <aname="Security"></a> Security
33
-
34
-
#### <aname="Permissions"></a> Permissions
35
-
Permission to execute **sp_spaceused** is granted to the **public** role. Only members of the **db_owner** fixed database role can specify the **\@updateusage** parameter.
32
+
Permission to run **sp_spaceused** is granted to the **public** role. Only members of the **db_owner** fixed database role can specify the **\@updateusage** parameter.
36
33
37
34
## <aname="SSMSProcedure"></a> Using SQL Server Management Studio
38
35
@@ -42,75 +39,79 @@ ms.custom: "seo-lt-2019"
42
39
43
40
2. Expand **Databases**.
44
41
45
-
3. Right-click a database, point to **Reports**, point to **Standard Reports,**, and then click**Disk Usage**.
42
+
3. Right-click a database, point to **Reports**, point to **Standard Reports**, and then select**Disk Usage**.
46
43
47
44
## <aname="TsqlProcedure"></a> Using Transact-SQL
48
45
49
46
#### To display data and log space information for a database by using sp_spaceused
50
47
51
48
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
52
49
53
-
2.From the Standard bar, click**New Query**.
50
+
2.On the Standard toolbar, select**New Query**.
54
51
55
-
3.Copy and paste the following example into the query window and click **Execute**. This example uses the [sp_spaceused](../../relational-databases/system-stored-procedures/sp-spaceused-transact-sql.md) system stored procedure to report disk space information for the entire database - tables and indexes.
52
+
3.Paste the following example into the query window and then select **Execute**. This example uses the [sp_spaceused](../../relational-databases/system-stored-procedures/sp-spaceused-transact-sql.md) system stored procedure to report disk space information for the entire database, including tables and indexes.
56
53
57
-
```sql
58
-
USE AdventureWorks2012;
59
-
GO
60
-
EXEC sp_spaceused;
61
-
GO
62
-
```
54
+
```sql
55
+
USE AdventureWorks2012;
56
+
GO
57
+
EXEC sp_spaceused;
58
+
GO
59
+
```
63
60
64
-
#### To display data space used by object and allocation unit for a database
61
+
#### To display data space used, by object and allocation unit, for a database
65
62
66
63
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
67
64
68
-
2. From the Standard bar, click **New Query**.
69
-
70
-
3. Copy and paste the following example into the query window and click **Execute**. This example queries [object catalog views](../system-catalog-views/object-catalog-views-transact-sql.md) to report disk space usage per table and within each table per [allocation unit](../pages-and-extents-architecture-guide.md#IAM).
71
-
72
-
```sql
73
-
SELECT
74
-
t.object_id,
75
-
OBJECT_NAME(t.object_id) ObjectName,
76
-
sum(u.total_pages) *8 Total_Reserved_kb,
77
-
sum(u.used_pages) *8 Used_Space_kb,
78
-
u.type_desc,
79
-
max(p.rows) RowsCount
80
-
FROM
81
-
sys.allocation_units u
82
-
joinsys.partitions p onu.container_id=p.hobt_id
83
-
joinsys.tables t onp.object_id=t.object_id
84
-
GROUP BY
85
-
t.object_id,
86
-
OBJECT_NAME(t.object_id),
87
-
u.type_desc
88
-
ORDER BY
89
-
Used_Space_kb desc,
90
-
ObjectName
91
-
```
65
+
2. On the Standard toolbar, select **New Query**.
66
+
67
+
3. Paste the following example into the query window and then select **Execute**. This example queries [object catalog views](../system-catalog-views/object-catalog-views-transact-sql.md) to report disk space usage per table and within each table per [allocation unit](../pages-and-extents-architecture-guide.md#IAM).
68
+
69
+
```sql
70
+
SELECT
71
+
t.object_id,
72
+
OBJECT_NAME(t.object_id) ObjectName,
73
+
sum(u.total_pages) *8 Total_Reserved_kb,
74
+
sum(u.used_pages) *8 Used_Space_kb,
75
+
u.type_desc,
76
+
max(p.rows) RowsCount
77
+
FROM
78
+
sys.allocation_units u
79
+
JOINsys.partitions p onu.container_id=p.hobt_id
80
+
81
+
JOINsys.tables t onp.object_id=t.object_id
82
+
83
+
GROUP BY
84
+
t.object_id,
85
+
OBJECT_NAME(t.object_id),
86
+
u.type_desc
87
+
ORDER BY
88
+
Used_Space_kb desc,
89
+
ObjectName;
90
+
91
+
```
92
92
93
93
#### To display data and log space information for a database by querying sys.database_files
94
94
95
95
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
96
96
97
-
2.From the Standard bar, click**New Query**.
97
+
2.On the Standard toolbar, select**New Query**.
98
98
99
-
3.Copy and paste the following example into the query window and click**Execute**. This example queries the [sys.database_files](../../relational-databases/system-catalog-views/sys-database-files-transact-sql.md) catalog view to return specific information about the data and log files in the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database.
99
+
3.Paste the following example into the query window then select**Execute**. This example queries the [sys.database_files](../../relational-databases/system-catalog-views/sys-database-files-transact-sql.md) catalog view to return specific information about the data and log files in the [!INCLUDE[ssSampleDBobject](../../includes/sssampledbobject-md.md)] database.
0 commit comments