dbTalk Databases Forums  

query/read database size?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss query/read database size? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rob Wahmann
 
Posts: n/a

Default query/read database size? - 07-28-2003 , 01:27 PM






I have a web-based admin section for a site and I would like to be able to
query the SQL Server database size and display it within my admin area. Is
there a function or method of doing this? My database is hosted by a third
party...

I appreciate any tips or advice you can provide!

Rob



Reply With Quote
  #2  
Old   
Simon Hayes
 
Posts: n/a

Default Re: query/read database size? - 07-28-2003 , 01:39 PM






"Rob Wahmann" <dotcomstudio (AT) sbcglobal (DOT) net> wrote

Quote:
I have a web-based admin section for a site and I would like to be able to
query the SQL Server database size and display it within my admin area. Is
there a function or method of doing this? My database is hosted by a third
party...

I appreciate any tips or advice you can provide!

Rob

Depending on what information you need, sp_helpdb might be good enough:

exec sp_helpdb MyDB

Simon




Reply With Quote
  #3  
Old   
Rob Wahmann
 
Posts: n/a

Default Re: query/read database size? - 07-28-2003 , 01:45 PM



Re: exec sp_helpdb MyDB

Thanks, Simon. I've seen a lot of those commands thrown around but how do I
actually run that? I'm pretty new to SQL Server and I've never set up a
stored procedure or a trigger... I'm doing everything right now with queries
and an ODBC connection. These sites are relatively small but I do need to
learn this stuff so I can build more robust apps.

Thanks!

Rob

"Simon Hayes" <sql (AT) hayes (DOT) ch> wrote

Quote:
"Rob Wahmann" <dotcomstudio (AT) sbcglobal (DOT) net> wrote in message
news:bWdVa.27537$BM.8963811 (AT) newssrv26 (DOT) news.prodigy.com...
I have a web-based admin section for a site and I would like to be able
to
query the SQL Server database size and display it within my admin area.
Is
there a function or method of doing this? My database is hosted by a
third
party...

I appreciate any tips or advice you can provide!

Rob


Depending on what information you need, sp_helpdb might be good enough:

exec sp_helpdb MyDB

Simon





Reply With Quote
  #4  
Old   
Simon Hayes
 
Posts: n/a

Default Re: query/read database size? - 07-28-2003 , 01:57 PM



"Rob Wahmann" <dotcomstudio (AT) sbcglobal (DOT) net> wrote

Quote:
Re: exec sp_helpdb MyDB

Thanks, Simon. I've seen a lot of those commands thrown around but how do
I
actually run that? I'm pretty new to SQL Server and I've never set up a
stored procedure or a trigger... I'm doing everything right now with
queries
and an ODBC connection. These sites are relatively small but I do need to
learn this stuff so I can build more robust apps.

Thanks!

Rob

<snip>

Any procedure beginning with sp_ is a system stored procedure - most are in
the master database (some are in msdb) but you can execute the ones in
master from any database on the server. I don't know much about ODBC, but if
you're already passing queries to the server and getting results, then try
to just pass the query text "exec sp_helpdb MyDB" (without the quotes, of
course), and handle the results like any other query.

One thing to be aware of is that stored procedures may return multiple
result sets, so you have to parse each result set to get all the
information. sp_helpdb returns two result sets. Books Online is an excellent
reference for all the system stored procedures - they are all listed under
the "System Stored Procedures" topic (at least assuming you have SQL2000 -
you didn't mention your version).

Simon




Reply With Quote
  #5  
Old   
Rob Wahmann
 
Posts: n/a

Default Re: query/read database size? - 07-28-2003 , 02:09 PM



Thanks again! I'm going to toy around with how to call the stored proc.

Regards,

Rob

"Simon Hayes" <sql (AT) hayes (DOT) ch> wrote

Quote:
"Rob Wahmann" <dotcomstudio (AT) sbcglobal (DOT) net> wrote in message
news:ebeVa.27550$BM.8967078 (AT) newssrv26 (DOT) news.prodigy.com...
Re: exec sp_helpdb MyDB

Thanks, Simon. I've seen a lot of those commands thrown around but how
do
I
actually run that? I'm pretty new to SQL Server and I've never set up a
stored procedure or a trigger... I'm doing everything right now with
queries
and an ODBC connection. These sites are relatively small but I do need
to
learn this stuff so I can build more robust apps.

Thanks!

Rob


snip

Any procedure beginning with sp_ is a system stored procedure - most are
in
the master database (some are in msdb) but you can execute the ones in
master from any database on the server. I don't know much about ODBC, but
if
you're already passing queries to the server and getting results, then try
to just pass the query text "exec sp_helpdb MyDB" (without the quotes, of
course), and handle the results like any other query.

One thing to be aware of is that stored procedures may return multiple
result sets, so you have to parse each result set to get all the
information. sp_helpdb returns two result sets. Books Online is an
excellent
reference for all the system stored procedures - they are all listed under
the "System Stored Procedures" topic (at least assuming you have SQL2000 -
you didn't mention your version).

Simon





Reply With Quote
  #6  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: query/read database size? - 07-28-2003 , 05:21 PM



Rob Wahmann (dotcomstudio (AT) sbcglobal (DOT) net) writes:
Quote:
Alrighty then... I've got the sp_helpdb prodecure returning results just
fine but it's showing the entire size of the database + log file. Is
there a way to specify the data file size only? I appreciate any tips!
If you specify a database name, you get two result sets, whereof the
second gives you sizes per file. You can also use sp_helpfile to get that
second result set only.

See further in Books Online. (Which you may not have installed, but see
my signature.)



--
Erland Sommarskog, SQL Server MVP, sommar (AT) algonet (DOT) se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


Reply With Quote
  #7  
Old   
Mark Etwaru
 
Posts: n/a

Default Re: query/read database size? - 07-29-2003 , 09:17 AM



A long time ago i've had this problem. Its just like the other guys said
use (sp_helpdb databasename) this will solve all your problems. This
will return you the total size with the LDF file included then the break
down of both files so this might be an advantage to your admin site.
However if you just want the individual file sizes then try (exec
sp_helpfile) and it will return the total sizes for both the MDF and LDF
files in one record. You can try both of these by typing them directly
into Query Analyzer.
Good Luck

"Real programmers don't work from 9 to 5. If any real programmers are
around at 9am it's because they were up all night."
-Anon.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.