Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 438205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:39:18+00:00 2026-05-12T20:39:18+00:00

I want to know status of every database across a SQL Server farm. I

  • 0

I want to know status of every database across a SQL Server farm. I was using:

select name,
       case status 
         when 32 then 'loading'
         when 128 then 'recovering'
         when 512 then 'offline'
         when 4096 then 'single user'
         when 64 then 'pre recovery'
         when 256 then 'not recovered'
         else 'Normal'
       end  
 from sysdatabases
where name not in('master','msdb','model','tempdb','reportserver','reportservertempdb','pubs','distribution','northwind')

But a friend told me that Status could be combination of 2 e.g. 32+128 = 32128.
How can I find database status using this figure?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T20:39:18+00:00Added an answer on May 12, 2026 at 8:39 pm

    All of the status numbers are shown in base 10 (decimal, our usual numbering system).
    However, you will note that all of the numbers are a multiple of 2 because
    they represent a bit position (base 2, 0 or 1).

    512 decimal = 200 hex = 0010 0000 0000 binary

    1024 decimal = 400 hex = 0100 0000 0000 binary

    The & is the bitwise AND operator. The logic table is:

    A   B    A AND B
    0   0       0
    1   0       0
    0   1       0
    1   1       1
    

    As you can see, if you AND two bits together, both bits must be 1 for the
    result to be 1. The AND ( & ) operator is used to mask all of the other bits to
    determine whether or not a particular bit is set.

    So, if you AND the status value with 512, then result will be 512 if the bit is
    set. Otherwise, it will be zero.

    Since 512 is the 10th bit (counting right to left), status & 512 will AND all of
    the bits in the status value with 0100 0000 0000. If the 10th bit is a 1 in the
    status value, the result will be 1, indicating that the OFFLINE option is turned
    on (set).

    To use the status columns effectively, you need at a least a rudimentary
    knowledge of binary and hexidecimal number systems. Actually, the same
    principles apply of any base (you just a way to represent each digit for large
    bases).

    Manjot
    This will get you started:

    1. You need to create a sproc that will convert varbinary into a hexstring – see Microsoft’s INFO: Converting Binary Data into Hexadecimal String
    2. The following sql:

      SELECT sus.status,
             sus.stat,
             CASE WHEN PATINDEX('%8', sus.stat) > 0 THEN 1 ELSE NULL END 'trunc. log on chkpt; set with sp_dboption.',
             CASE WHEN PATINDEX('%1%', sus.stat) = 9 THEN 1 ELSE NULL END 'torn page detection, set with sp_dboption.',
             CASE WHEN PATINDEX('%1%', sus.stat) = 8 THEN 1 ELSE NULL END 'loading.',
             CASE WHEN PATINDEX('%1%', sus.stat) = 7 THEN 1 ELSE NULL END 'pre recovery.'
        FROM (SELECT t.status,
                     sp_hexadecimal(CONVERT(varbinary(8), t.status)) 'stat'
                FROM SYSDATABASES t) sus
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 100 devices that I want to know the status of every 10
I have a postgres database that I want to know some quick stats. For
want to know why String behaves like value type while using ==. String s1
I want to know that can we build a data object using jquery/json, which
I want to know if you know how to date diff every 3 days
i want know how i can manage multiple twitter account on iOS in my
i want know if is possible, to get a specific element value of a
please help me. I want know about what types of flags to run an
I have an android app it displays web view.I want know the app idle
I'm making a chat responder for a game and i want know if there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.