I can’t figure out what state my database is in. Sysdatabases shows me status values that don’t exist in books online like 532.

Filed under: Administration, I'm a Newbie, SQL Server 2005 — Ari Weil at 6:51 am on Monday, January 28, 2008

First, let’s dispense with the standard answer, “If you upgrade to SQL Server 2005 (or if you already have) the new system management and catalog views will provide you with more useful information.” While this is a stock answer, it happens to be very true in this particular scenario.

sysdatabases is the SQL Server 2000 catalog view whose status column displays:

1 = autoclose (ALTER DATABASE)
4 = select into/bulkcopy (ALTER DATABASE using SET RECOVERY)
8 = trunc. log on chkpt (ALTER DATABASE using SET RECOVERY)
16 = torn page detection (ALTER DATABASE)
32 = loading
64 = pre recovery
128 = recovering
256 = not recovered
512 = offline (ALTER DATABASE)
1024 = read only (ALTER DATABASE)
2048 = dbo use only (ALTER DATABASE using SET RESTRICTED_USER)
4096 = single user (ALTER DATABASE)
32768 = emergency mode
4194304 = autoshrink (ALTER DATABASE)
1073741824 = cleanly shutdown
Multiple bits can be ON at the same time.

The last sentence about the multiple bits is what’s getting you. In your case, a database showing a status of 532 is set to allow select into/bulkcopy (BULK_LOGGED recovery), to enable torn page detection and is currently offline (4 + 16 + 512 = 532).

sys.databases is the SQL Server 2005 catalog view and offers more insight (while requiring you to query more columns, which is fair in my opinion). Using this view you’ll find columns identifying statuses and configuration options both numerically and using descriptions. So, using your status of 532 again, but by querying sys.databases, you’ll see:

[recovery_model]=2,
[recovery_model_desc]=’BULK_LOGGED’,
[page_verify_option]=1,
[page_verify_option_desc]=’TORN_PAGE_DETECTION’,
[state]=6,
[state_desc]=’OFFLINE’

Hope that helps.

2 Comments »

Comment by Hugo

January 28, 2008 @ 4:52 pm

Where I can get the reference meaning of the database status number? Some of my db are in 540, 4194844 or 4194840 status and I don“t know the meaning.

Thanks.

Comment by Ari Weil

January 29, 2008 @ 1:24 am

Hi Hugo, you need to understand that since the status column displays values for multiple bits simultaneously you’ll have to calculate the value (and to my knowledge nobody’s posted all the various bit combination possibilities).

To specifically answer your question about the three values:
512 (offline)
+ 16 (torn page detection)
+ 8 (trunc. log on chkpt)
+ 4 (select into/bulkcopy)
=540

540 (see above)
+4194304 (autoshrink)
=4194844

419840 includes the options from the previous example, without select into/bulkcopy enabled (4194844 - 4).

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>