master..sysdatabases status code

  • Hello!

    I want to use the status code from the master..sysdatabases table, I've found the following status code:

    128 -->recovering

    256 --> not recovered

    512 --> offline

    2048 --> dbo use only

    4096 --> single user

    32768 --> emergency mode

    Now when I do a select * from master..sysdatabases than the status is 65536 (the database is online) now when I bring the database offline the status changes to 66048, from the information I've found at the Internet the code must be 512.

    Can someone explain this error codes ? I don't understand why they are totaly difference from them i've found on the Internet.

    Thnx

  • These are the official statuscodes from the SQL2000 documentation

    Status bits, some of which can be set by the user with sp_dboption (read only, dbo use only, single user, and so on):

    1 = autoclose; set with sp_dboption.

    4 = select into/bulkcopy; set with sp_dboption.

    8 = trunc. log on chkpt; set with sp_dboption.

    16 = torn page detection, set with sp_dboption.

    32 = loading.

    64 = pre recovery.

    128 = recovering.

    256 = not recovered.

    512 = offline; set with sp_dboption.

    1024 = read only; set with sp_dboption.

    2048 = dbo use only; set with sp_dboption.

    4096 = single user; set with sp_dboption.

    32768 = emergency mode.

    4194304 = autoshrink.

    1073741824 = cleanly shutdown.

    Obviously this list is not complete, because you couldn't get a value of 65536 by just combining these.

    [font="Verdana"]Markus Bohse[/font]

  • Oops, I should have read it more slowly.

    Actually you're if you look at your code 65536 and add the 512 for Offline the result is 66048.

    The value in sysdatabases is the sum of all active database options.

    You can use a bitwise operator to check for a certain status.

    SELECT CASE WHEN 66048& 512 = 512

    THEN 'Offline'

    ELSE 'ONLINE'

    END

    [font="Verdana"]Markus Bohse[/font]

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply