Skip to content

Commit f7f68c9

Browse files
authored
Merge pull request #19567 from v-albemi/display-data-and-log-space-information-for-a-database
edit pass: display-data-and-log-space-information-for-a-database
2 parents 1a8da8e + 364ff18 commit f7f68c9

1 file changed

Lines changed: 55 additions & 54 deletions

File tree

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Display data & log space info for a database"
33
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.
4-
ms.date: "08/01/2016"
4+
ms.date: "06/16/2021"
55
ms.prod: sql
66
ms.prod_service: "database-engine, sql-database, synapse-analytics, pdw"
77
ms.reviewer: ""
@@ -22,17 +22,14 @@ ms.author: wiassaf
2222
monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current"
2323
ms.custom: "seo-lt-2019"
2424
---
25-
# Display Data and Log Space Information for a Database
25+
# Display data and log space information for a database
2626
[!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)].
2828

2929

30-
## <a name="BeforeYouBegin"></a> Before You Begin
30+
## <a name="BeforeYouBegin"></a> Before you begin
3131

32-
### <a name="Security"></a> Security
33-
34-
#### <a name="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.
3633

3734
## <a name="SSMSProcedure"></a> Using SQL Server Management Studio
3835

@@ -42,75 +39,79 @@ ms.custom: "seo-lt-2019"
4239

4340
2. Expand **Databases**.
4441

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**.
4643

4744
## <a name="TsqlProcedure"></a> Using Transact-SQL
4845

4946
#### To display data and log space information for a database by using sp_spaceused
5047

5148
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
5249

53-
2. From the Standard bar, click **New Query**.
50+
2. On the Standard toolbar, select **New Query**.
5451

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.
5653

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+
```
6360

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
6562

6663
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
6764

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-
join sys.partitions p on u.container_id = p.hobt_id
83-
join sys.tables t on p.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+
JOIN sys.partitions p on u.container_id = p.hobt_id
80+
81+
JOIN sys.tables t on p.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+
```
9292

9393
#### To display data and log space information for a database by querying sys.database_files
9494

9595
1. Connect to the [!INCLUDE[ssDE](../../includes/ssde-md.md)].
9696

97-
2. From the Standard bar, click **New Query**.
97+
2. On the Standard toolbar, select **New Query**.
9898

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.
100100

101-
```sql
102-
USE AdventureWorks2012;
103-
GO
104-
SELECT file_id, name, type_desc, physical_name, size, max_size
105-
FROM sys.database_files ;
106-
GO
101+
```sql
102+
USE AdventureWorks2012;
103+
GO
104+
SELECT file_id, name, type_desc, physical_name, size, max_size
105+
FROM sys.database_files;
106+
107+
GO
107108

108-
```
109+
```
109110

110-
## See Also
111+
## See also
111112

112113
[SELECT &#40;Transact-SQL&#41;](../../t-sql/queries/select-transact-sql.md)
113114
[sys.database_files &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-database-files-transact-sql.md)
114115
[sp_spaceused &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/sp-spaceused-transact-sql.md)
115-
[Add Data or Log Files to a Database](../../relational-databases/databases/add-data-or-log-files-to-a-database.md)
116-
[Delete Data or Log Files from a Database](../../relational-databases/databases/delete-data-or-log-files-from-a-database.md)
116+
[Add data or log files to a database](../../relational-databases/databases/add-data-or-log-files-to-a-database.md)
117+
[Delete data or log files from a database](../../relational-databases/databases/delete-data-or-log-files-from-a-database.md)

0 commit comments

Comments
 (0)