Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

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.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

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

Navigation

Google Ads

Getting The Database State For All The Databases In SQL Server

From Wiki

Jump to: navigation, search

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

In SQL Server 2005 and up you can use the sys.databases catalog view

  1. SELECT name,state_desc,STATE
  2. 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

584 Rating: 2.7/5 (6 votes cast)