Friday, March 30, 2012

query/read database size?

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"Rob Wahmann" <dotcomstudio@.sbcglobal.net> wrote in message
news:bWdVa.27537$BM.8963811@.newssrv26.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|||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@.hayes.ch> wrote in message
news:3f256df9$1_2@.news.bluewin.ch...
> "Rob Wahmann" <dotcomstudio@.sbcglobal.net> wrote in message
> news:bWdVa.27537$BM.8963811@.newssrv26.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|||"Rob Wahmann" <dotcomstudio@.sbcglobal.net> wrote in message
news:ebeVa.27550$BM.8967078@.newssrv26.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|||Thanks again! I'm going to toy around with how to call the stored proc.

Regards,

Rob

"Simon Hayes" <sql@.hayes.ch> wrote in message
news:3f257215_4@.news.bluewin.ch...
> "Rob Wahmann" <dotcomstudio@.sbcglobal.net> wrote in message
> news:ebeVa.27550$BM.8967078@.newssrv26.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|||Rob Wahmann (dotcomstudio@.sbcglobal.net) writes:
> 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@.algonet.se

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

No comments:

Post a Comment