In production we do not want customers to have databases with autoclose or autoshrink. This is code to list all such databases in one instance.
SELECT [name] AS DatabaseName
, CONVERT(varchar(100),DATABASEPROPERTYEX([Name] , 'Recovery')) AS RecoveryType
, CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsAutoClose')) AS AutoClose
, CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsAutoShrink')) AS AutoShrink
, CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsSuspect')) AS Suspect
, CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsOffline')) AS Offline
, CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsAutoCreateStatistics')) AS AutoCreateStatistics
, CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsAutoUpdateStatistics')) AS AutoUpdateStatistics
FROM master.dbo.sysdatabases
where
dbid >4 and(
CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsOffline'))=1
or CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsSuspect')) =1
or CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsAutoUpdateStatistics')) =0
or CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsAutoCreateStatistics')) =0
or CONVERT(varchar(100),DATABASEPROPERTYEX([Name] , 'Recovery')) <> 'Full'
or CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsAutoClose')) > 0
or CONVERT(varchar(10),DATABASEPROPERTYEX([Name] , 'IsAutoShrink')) > 0)
order by databasename
No comments:
Post a Comment