Why would this query return an error that mentions an entirely different database being offline?


trying list of fragmented indexes based on database name.  however, 

select	count(*) tablefragover80pctcount sys.dm_db_index_physical_stats (null, null, null, null, null )as ts inner join sys.tables t on t.[object_id] = ts.[object_id] inner join sys.indexes on i.[object_id] = ts.[object_id] inner join sys.databases db on ts.database_id = db.database_id db.name = 'my db name' , ts.avg_fragmentation_in_percent  > 80.00

the error back 

msg 942, level 14, state 4, line 1
database 'very different db' cannot opened because offline.

i know there database on server offline, 2 or 3, not 1 im trying information about.  what cause above query have trouble getting index info caused entirely different database being offline?


from sys.dm_db_index_physical_stats (null, null, null, null, null )as ts


see msdn sys.dm_db_index_physical_stats ;  first parameter database id; if pass null here, databases scanned, offline one.

olaf helper

[ blog] [ xing] [ mvp]




SQL Server  >  SQL Server Database Engine



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user