Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
Getting The Database State For All The Databases In SQL Server
From Wiki
You want to quickly know the status for all your databases. In SQL Server 2000 you can use the sp_helpdb proc.
The proc sp_helpdb returns a resultset with all your databases, look at the name and the status column
- SP_HELPDB
In SQL Server 2005 and up you can use the sys.databases catalog view
- SELECT name,state_desc,STATE
- FROM sys.databases
I have included the state column, this column holds a numeric value, the state_desc column holds the description for that numeric value. Below is a table showing you what those are
0 = ONLINE
1 = RESTORING
2 = RECOVERING
3 = RECOVERY_PENDING
4 = SUSPECT
5 = EMERGENCY
6 = OFFLINE
Contributed by: --SQLDenis 18:28, 4 September 2008 (GMT)
Part of SQL Server Admin Hacks



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.