sql Database sizes

Declare @DBName varchar(50)
Declare @cmdExec nvarchar(2048)

Declare db_cursor Cursor For
	Select [name] From sys.databases Where [name] Not In ('master','tempdb','model','msdb') Order By [name] Asc

Open db_cursor
Fetch Next From db_cursor Into @DBName

While @@Fetch_Status = 0
Begin
	Set @cmdExec = 'Use ' + @DBName + ';Execute sp_spaceused;'
	--Execute sp_executeSQL @cmdExec
	Print @cmdExec

	Fetch Next From db_cursor Into @DBName
End

Close db_cursor
Deallocate db_cursor
Gets the sizes of databases on a server.

Updated: Saturday 9th October 2010, 07:31pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.