|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Today @ 8:32 AM
Points: 795,
Visits: 1,982
|
|
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
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Friday, November 14, 2008 10:47 AM
Points: 1,
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
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Today @ 8:32 AM
Points: 795,
Visits: 1,982
|
|
Sorry about the late reply, was swamped at work. :)
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
|
|
|
|