Solved

sp_spaceused - database_size - sql 2000

Posted on 2010-09-15
5
472 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:ScottPletcher
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:ScottPletcher
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now