• subscribe
November 02, 2005 12:00 AM

Using T-SQL to Check Database Memory

SQL Server Pro
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.



ARTICLE TOOLS

Comments
  • Karen
    4 years ago
    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

  • Joseph
    4 years ago
    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
    4 years ago
    Nov 24, 2008

    By "memory" you mean disk.

You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...