January 14, 2008 at 1:41 am
is there a simple way of identifying offline databases on an instance from a system table? there is a status column in sysdatabases but i cant find a way of showing databases that are offline. any ideas?
January 14, 2008 at 2:57 am
Try using DATABASEPROPERTY() function with the 'IsOffline' property.
Paul
January 14, 2008 at 3:04 am
problem with that is you need to change the database context for each database or create some kind of loop to change the database name in the function. i was hoping that it would be easy to extract a value from sysdatabases (or somewhere else) so i can identify all the offline databases in an instance using one sql query.
January 14, 2008 at 3:37 am
actually, i think this works.
SELECT name FROM master..sysdatabases
WHERE substring(convert(binary, status),len(convert(binary, status))-1,1) <> 0x02
January 15, 2008 at 1:46 pm
How about this:
SELECT [name]
FROM master.dbo.sysdatabases
WHERE CAST(DATABASEPROPERTY([name], 'IsOffline') as int) = 1
ORDER BY [name]
January 16, 2008 at 6:13 am
This works too:
SELECT [name] AS Name, dbid AS DBID,
DATABASEPROPERTYEX([name], 'Status')AS DBStatus
FROM master.dbo.sysdatabases
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply