Solved

sp_spaceused - database_size - sql 2000

Posted on 2010-09-15
5
479 Views
Last Modified: 2012-05-10
There is store procedure sp_spaceused this give information about database size and some other database related information. One of the output column is database_size

Does anyone know in which table "database_size" field is stored? thanks
0
Comment
Question by:tech2010
  • 2
  • 2
5 Comments
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 33683333
It's not directly stored in that way.  That value is likely a summation of other values in system tables.

In SQL 2000, I think you have to use dbo.sysindexes to get the relevant sizes.  Note that even a table w/o any index is in sysindexes, with an indid = 0 (0 = heap, 1 = clus index).
0
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 33683368
Its from dbo.sysfiles and the query involved here:

select sum(convert(bigint,case when status & 64 = 0 then size else 0 end)) dbsize,
sum(convert(bigint,case when status & 64 <> 0 then size else 0 end)) logsize
            from dbo.sysfiles
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 33683480
You can always go to master and look at the code for
sp_spaceused

Yeah, sysindexes wouldn't have log size, only data size.
0
 

Author Comment

by:tech2010
ID: 33683600
how can sum data + log size and then use xp_sendmail to fire an email if total sum is > 100
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 33684197
>> how can sum data + log size

It can be summed like this

select sum(convert(bigint,case when status & 64 = 0 then size else 0 end)) +
sum(convert(bigint,case when status & 64 <> 0 then size else 0 end)) total_size
from dbo.sysfiles

Send the result of the above query using xp_sendmail like:

EXEC xp_sendmail @recipients = 'emailid',
   @query = 'select sum(convert(bigint,case when status & 64 = 0 then size else 0 end)) + sum(convert(bigint,case when status & 64 <> 0 then size else 0 end)) total_size from dbo.sysfiles',
   @subject = 'Result',
   @message = 'Result of the query:',
   @attach_results = 'TRUE', @width = 250
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS 2013 - Creating a summarized report 19 35
SSRS 2013 - Overlapping reports 2 22
SQL Insert parts by customer 12 34
MS SQL Server COnditional Where statement 7 59
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question