Using T-SQL to Check Database Memory

When I use the TaskPad in Enterprise Manager to check a database's allocated, used, and free space (as reported on the General tab), the values I see don't match the values I get when I use the sp_HelpDB and sp_Spaceused stored procedures. For example, when I checked one of my databases today, I got the following information:

  • In TaskPad, Enterprise Manager reported that the database had 211549.75MB of allocated space, 110294.44MB of used space, and 101255.31MB of free space.
  • For the same database, the sp_Spaceused stored procedure told me I had 212113.50MB of allocated space and 19541.14MB of unallocated space.
  • The sp_helpDB stored procedure reported that I had an MDF file size of 211549.75MB.

Can I use T-SQL to return the same information that I see when I use the TaskPad?

To generate the information on the TaskPad, Enterprise Manager uses a combination of the following four queries.

EXEC sp_spaceused
SELECT fileid, name, filename, size, growth, status, maxsize
FROM dbo.sysfiles WHERE (status & 0x40) <>0
DBCC sqlperf(logspace)
DBCC showfilestats

Enterprise Manager uses SQL-DMO to retrieve the information.

Discuss this Article 3

Joseph (not verified)
on Nov 24, 2008
By "memory" you mean disk usage. I am interested in finding how to tell which database & tables are consuming memory (not disk).
Joseph (not verified)
on Nov 24, 2008
By "memory" you mean disk.
KBemowski
on Nov 24, 2008
Shaunt Khaldtiance wrote a stored procedure, usp_SpaceUsedAnalyzer, to keep track of databases' growth and how much space is being used by each table and index in those databases. This stored procedure extends the functionality of the sp_spaceused system stored procedure to present more detailed information. You can read about the usp_SpaceUsedAnalyzer stored procedure and download its code in the article "Track Database Disk-Space Usage on a Granular Level" at http://sqlmag.com/Articles/ArticleID/100213/100213.html. This article is open to registered users. I hope this stored procedure is what you're looking for. If not, please let me know. Karen Bemowski, senior editor SQL Server Magazine, Windows IT Pro

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Mike Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
Vision road sign
May 6, 2013
blog

Cheaters Never Win, Even in TPC Benchmarks

In this portion of the series on database benchmarking, I want to tell you about one of my favorite aspects of the TPC benchmarks – CHEATING....More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.