On one of my servers this query
— Find missing index warnings for cached plans in the current database (Query 55) (Missing Index Warnings)
— Note: This query could take some time on a busy instance
SELECT TOP(25) OBJECT_NAME(objectid) AS [ObjectName],
cp.objtype, cp.usecounts, cp.size_in_bytes, query_plan
FROM sys.dm_exec_cached_plans AS cp WITH (NOLOCK)
CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp
WHERE CAST(query_plan AS NVARCHAR(MAX)) LIKE N’%MissingIndex%’
AND dbid = DB_ID()
ORDER BY cp.usecounts DESC OPTION (RECOMPILE);
——
Gives this result:
Msg 942, Level 14, State 4, Line 3
Database ‘xxx’ cannot be opened because it is offline.
(this is a different user database than the current database context)
I can’t see why SQL Server wants to access the other database by looking at the query.
It’s this version of SQL Server 2012 (SP3) – 11.0.6020.0 (X64)
]]>Thanks for catching that. I have fixed that now.
]]>