Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 93903
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:25:03+00:00 2026-05-10T23:25:03+00:00

I am attempting to programmatically monitor the size of a SQL Server database, so

  • 0

I am attempting to programmatically monitor the size of a SQL Server database, so that my admin section of my web app can report it, and I can use that to execute some cleanup SPs, to clear log files, etc.

I use the following code to calculate the size of the tables, per SO recommendation:

CREATE TABLE #t (name SYSNAME, rows CHAR(11), reserved VARCHAR(18), data VARCHAR(18), index_size VARCHAR(18), unused VARCHAR(18))EXEC sp_msforeachtable 'INSERT INTO #t EXEC sp_spaceused ''?'''-- SELECT * FROM #t ORDER BY name-- SELECT name, CONVERT(INT, SUBSTRING(data, 1, LEN(data)-3)) FROM #t ORDER BY nameSELECT SUM(CONVERT(INT, SUBSTRING(data, 1, LEN(data)-3))) FROM #tDROP TABLE #t 

When I run this against my small sample database, I get a total sum value of ~6.8 megabytes. When I look at the properties of my database, it shows 15.5 megabytes.

I have the following questions:
1. What else can make up the difference?
2. Can this difference be described as ‘overhead’, which will only grow at a fraction of the pace as other data grows (rough estimate is all I need for this).
3. Stored Procedures, Functions, Views, Triggers are in this ‘overhead’ space? Is there a way to calculate these?
4. Is there another way to get the WHOLE database size? I really just want a simple way to get the REAL size.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T23:25:03+00:00Added an answer on May 10, 2026 at 11:25 pm

    The difference, in my opinion, is due to the fact that the size you see in the ‘Properties’ page is calculated by querying the table .sys.database_files, which counts the number of 8KB pages allocated by each database file.

    To obtain the same result, simply run the following query (SQL Server 2005):

     SELECT   SUM([size] * 8) / 1024  AS DB_Size -- Field 'size' contains the number of 8 KB pages contained in each file FROM   [db_name_here].sys.database_files 

    More information about sys.database_files on MSDN website.

    Hope this helps. 🙂

    Diego

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 248k
  • Answers 248k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you want to know what response size browsers need… May 13, 2026 at 8:49 am
  • Editorial Team
    Editorial Team added an answer The logical and is short circuiting. That means that if… May 13, 2026 at 8:49 am
  • Editorial Team
    Editorial Team added an answer The code in onClick() is simply creating the dialog -… May 13, 2026 at 8:49 am

Related Questions

I am attempting to programmatically add a test project to a solution. However when
To quickly summarise my question: Is it feasible to programmatically change the name of
I am attempting to get the current users RAM configuration. I would like to
I am attempting to rewrite my ForestPad application utilizing WPF for the presentation layer.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.