SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Monitor file growth - a better way for sp_spaceused


Monitor file growth - a better way for sp_spaceused

Author
Message
GabyYYZ
GabyYYZ
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2973 Visits: 2336
Comments posted to this topic are about the item Monitor file growth - a better way for sp_spaceused

Gaby
________________________________________________________________
"In theory, theory and practice are the same. In practice, they are not."
- Albert Einstein

Ian Molyneaux
Ian Molyneaux
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 3
Looks good but how do you go about getting the same information for all databases on a SQL instance.
i.e I'm trying to check when a database is about to auto-extend and I just want the available space for DB1, DB2 etc.
The USE command doesnt seem to permit the construct
USE @dbName. You have to implicitly specify the database i.e USE "DB1"

KR
Ian
GabyYYZ
GabyYYZ
SSCrazy
SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)SSCrazy (3K reputation)

Group: General Forum Members
Points: 2973 Visits: 2336
Sorry about the late reply, was swamped at work. Smile

One way to do it for each database is either the undocumented sp_msforeachdb feature or roll it into a loop. You can use cursors but I personally don't use them much. Here is a non-cursor version:


declare @db_list table (dbname sysname)
declare @dbname sysname, @query varchar(8000)

insert @db_list(dbname)
select name from sys.databases
where name not in ('tempdb', 'master', 'msdb', 'model') -- feel free to change as needed
order by name asc

while (select count(*) from @db_list) > 0 -- one way to iterate, the list is small enough that this will have no impact
begin
select top 1 @dbname = dbname from @db_list
select @query = 'use ' + quotename(@dbname) + '; INSERT THE NEW SP_SPACEUSED SCRIPT HERE'
exec(@query)
delete from @db_list where dbname = @dbname
end



Hope this helps and good luck.

Gaby A.
Toronto, ON

Gaby
________________________________________________________________
"In theory, theory and practice are the same. In practice, they are not."
- Albert Einstein

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search