November 02, 2005 08:02 PM

Using T-SQL to Check Database Memory

Rating: (0)
SQL Server Magazine
InstantDoc ID #48339

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.

Add a Comment

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

Karen11/24/2008 9:24:22 AM


By "memory" you mean disk usage. I am interested in finding how to tell which database & tables are consuming memory (not disk).

Joseph11/24/2008 4:57:41 AM


By "memory" you mean disk.

Joseph11/24/2008 4:56:12 AM


You must log on before posting a comment.

Are you a new visitor? Register Here
GOOGLE LINKS
SPONSORED LINKS
FEATURED LINKS