Beyondrelational

Wednesday, June 9, 2010

How to list space usage for all databases?

Execute the following script in Query Editor to display space used information for all databases:



use master
go


create table #systemdbs (name sysname)
insert #systemdbs
select 'master'
union all select 'msdb'
union all select 'model'
union all select 'tempdb'


declare @Command nvarchar(1012)
set @Command= 'if not exists (select * from #systemdbs where name = ''?'') use ? ; exec sp_spaceused @updateusage=true'
print @Command


exec sp_MSforeachdb @command1 = @Command


drop table #systemdbs


go

No comments:

Post a Comment