If you plug this query into a SQL Server Central Management server you’ll have a snapshot of all your instances that are part of the CMS.
This query will return the database name, the overall size of the database including all data and log files, the create date, owner, compatibility level, online vs offline, and update stats info.
This query will return the database name, the overall size of the database including all data and log files, the create date, owner, compatibility level, online vs offline, and update stats info.
It’s interesting to find databases owned by staff that are no longer around, compatibility levels to old versions for no obvious reason, and create and update stats that are turned off.
So here’s the query:
Select Convert(int, Convert(char, current_timestamp, 112)) as CaptureDate
, d.database_id
, d.[name]
, CAST(SUM(mf.size * 8096.0 / 1000000000) AS NUMERIC(18, 2)) AS [db_size (G)]
, d.recovery_model_desc AS [Recovery Model]
, d.create_date
, suser_sname(d.owner_sid) AS [Owner]
, d.[compatibility_level]
, d.state_desc AS [State]
, d.is_auto_create_stats_on
, d.is_auto_update_stats_on
FROM sys.databases d
Inner Join sys.master_files mf
ON mf.database_id = d.database_id
WHERE d.database_id > 4 — Exclude the system databases.
GROUP BY d.database_id
, d.[name]
, d.recovery_model_desc
, d.create_date
, d.owner_sid
, d.[compatibility_level]
, d.state_desc
, d.is_auto_create_stats_on
, d.is_auto_update_stats_on
, d.database_id
, d.[name]
, CAST(SUM(mf.size * 8096.0 / 1000000000) AS NUMERIC(18, 2)) AS [db_size (G)]
, d.recovery_model_desc AS [Recovery Model]
, d.create_date
, suser_sname(d.owner_sid) AS [Owner]
, d.[compatibility_level]
, d.state_desc AS [State]
, d.is_auto_create_stats_on
, d.is_auto_update_stats_on
FROM sys.databases d
Inner Join sys.master_files mf
ON mf.database_id = d.database_id
WHERE d.database_id > 4 — Exclude the system databases.
GROUP BY d.database_id
, d.[name]
, d.recovery_model_desc
, d.create_date
, d.owner_sid
, d.[compatibility_level]
, d.state_desc
, d.is_auto_create_stats_on
, d.is_auto_update_stats_on
No comments:
Post a Comment
Hi,
Thanks for your visit to this blog.
We would be happy with your Queries/Suggestions.