Display data and log infinite information for a database

Applies to: yesSQL Server (all supported versions) YesAzure SQL Database YesAzure SQL Managed Instance yesAzure Synapse Analytics yesAnalytics Platform System (PDW)

This commodity describes how to display the data and log space data for a database in SQL Server 2019 (15.x) by using SQL Server Management Studio or Transact-SQL.

Before you begin

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.

Using SQL Server Direction Studio

To display data and log space data for a database

  1. In Object Explorer, connect to an example of SQL Server and and then aggrandize that instance.

  2. Expand Databases.

  3. Correct-click a database, point to Reports, point to Standard Reports, and then select Deejay Usage.

Using Transact-SQL

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

  1. Connect to the Database Engine.

  2. On the Standard toolbar, select New Query.

  3. Paste the post-obit example into the query window and so select Execute. This example uses the sp_spaceused organisation stored procedure to study disk space data for the unabridged database, including tables and indexes.

                      Employ AdventureWorks2012;   Go   EXEC sp_spaceused;   GO                                  

To display information space used, past object and allocation unit, for a database

  1. Connect to the Database Engine.

  2. On the Standard toolbar, select New Query.

  3. Paste the following example into the query window and and so select Execute. This case queries object catalog views to report disk space usage per table and within each table per allocation unit of measurement.

                      SELECT   t.object_id,   OBJECT_NAME(t.object_id) ObjectName,   sum(u.total_pages) * 8 Total_Reserved_kb,   sum(u.used_pages) * 8 Used_Space_kb,   u.type_desc,   max(p.rows) RowsCount FROM   sys.allocation_units u   Join sys.partitions p on u.container_id = p.hobt_id    Bring together sys.tables t on p.object_id = t.object_id  GROUP By   t.object_id,   OBJECT_NAME(t.object_id),   u.type_desc Gild By   Used_Space_kb desc,   ObjectName;                                  

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

  1. Connect to the Database Engine.

  2. On the Standard toolbar, select New Query.

  3. Paste the following example into the query window then select Execute. This example queries the sys.database_files catalog view to render specific information about the data and log files in the AdventureWorks2012 database.

                      Utilise AdventureWorks2012;   Go   SELECT file_id, name, type_desc, physical_name, size, max_size   FROM sys.database_files;    GO                                  

See besides

SELECT (Transact-SQL)
sys.database_files (Transact-SQL)
sp_spaceused (Transact-SQL)
Add data or log files to a database
Delete data or log files from a database