June 8, 2010 at 3:10 pm
Hi everyone, I've taken the SQL found here to query autogrow status: http://beyondrelational.com/blogs/jacob/archive/2009/06/04/how-to-query-the-auto-growth-properties-of-a-sql-server-database-using-tsql.aspx
and combined it with SP_MSforeachdb like this:
DECLARE @command varchar(1000)
SELECT @command = 'USE [?] IF ''[?]'' NOT IN (''[master]'', ''[model]'', ''[msdb]'', ''[tempdb]'')
SELECT name as [?],
CASE
WHEN is_percent_growth = 0
THEN ''By '' + LTRIM(STR(growth * 8.0 / 1024,10,1)) + '' MB, ''
ELSE
''By '' + CAST(growth AS VARCHAR) + '' percent, ''
END +
CASE
WHEN max_size = -1 THEN ''unrestricted growth''
ELSE ''restricted growth to '' +
LTRIM(STR(max_size * 8.0 / 1024,10,1)) + '' MB''
END AS Autogrow
FROM sys.database_files'
EXEC sp_MSforeachdb @command
Each time I run the query on the same instance, I get a different number of output rows. Certain seemingly random databases are excluded from the results. Any ideas why that might be?
June 8, 2010 at 4:51 pm
What happens if you try this?
DECLARE @command varchar(1000)
SELECT @command = 'IF ''[?]'' NOT IN (''[master]'', ''[model]'', ''[msdb]'', ''[tempdb]'')
SELECT name as [?],
CASE
WHEN is_percent_growth = 0
THEN ''By '' + LTRIM(STR(growth * 8.0 / 1024,10,1)) + '' MB, ''
ELSE
''By '' + CAST(growth AS VARCHAR) + '' percent, ''
END +
CASE
WHEN max_size = -1 THEN ''unrestricted growth''
ELSE ''restricted growth to '' +
LTRIM(STR(max_size * 8.0 / 1024,10,1)) + '' MB''
END AS Autogrow
FROM [?].sys.database_files'
EXEC sp_MSforeachdb @command
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
June 8, 2010 at 11:36 pm
no need for a parameter......
just run:
EXEC sp_MSforeachdb 'USE [?] IF ''[?]'' NOT IN (''[master]'', ''[model]'', ''[msdb]'', ''[tempdb]'')
SELECT name as [?],
CASE
WHEN is_percent_growth = 0
THEN ''By '' + LTRIM(STR(growth * 8.0 / 1024,10,1)) + '' MB, ''
ELSE
''By '' + CAST(growth AS VARCHAR) + '' percent, ''
END +
CASE
WHEN max_size = -1 THEN ''unrestricted growth''
ELSE ''restricted growth to '' +
LTRIM(STR(max_size * 8.0 / 1024,10,1)) + '' MB''
END AS Autogrow
FROM sys.database_files'
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
This thing is addressing problems that dont exist. Its solution-ism at its worst. We are dumbing down machines that are inherently superior. - Gilfoyle
June 9, 2010 at 9:13 am
Hi WayneS,
Thanks for responding. The changes that you suggested also worked but as before, I get different results each time I run this query. The first time, 68 rows were returned then running it again, 38 rows were returned.
WayneS (6/8/2010)
What happens if you try this?
June 9, 2010 at 9:16 am
Hi Henrico, thanks for responding.
It does work without the variable but I still get the same issue. 68 rows returned sometimes and 38 rows returned other times.
Henrico Bekker (6/8/2010)
no need for a parameter......just run:
June 9, 2010 at 9:56 am
I've compared the output of the querys and for some reason, sometimes the query just gives up part way through. If I keep executing the query, it will eventually give me a full output.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply