我希望能够运行查询以获取有关数据库状态的关键信息。即,我希望查询能够判断数据库是否处于良好状态。
这是我为此检查继承的查询:
SELECT name AS [SuspectDB],
DATABASEPROPERTY(name, N'IsSuspect') AS [Suspect],
DATABASEPROPERTY(name, N'IsOffline') AS [Offline],
DATABASEPROPERTY(name, N'IsEmergencyMode') AS [Emergency],
has_dbaccess(name) AS [HasDBAccess]
FROM sysdatabases
WHERE (DATABASEPROPERTY(name, N'IsSuspect') = 1)
OR (DATABASEPROPERTY(name, N'IsOffline') = 1)
OR (DATABASEPROPERTY(name, N'IsEmergencyMode') = 1)
OR (has_dbaccess(name) = 0)
如果该查询返回任何结果,则假定数据库处于可疑状态或潜在的不良状态。
有一个更好的方法吗?