How to calculate status from db..sysfiles?

  • Hello,

    Can somebody tell me how to calculate status that is given via db..sysfiles?

    I see here that line

    select *

    from db..[sysfiles]

    where (status & 64 = 0)

    will give me only information about data file. But what if I would like to have information about log ?

  • select *-- data files (*.MDF)

    from sysfiles

    where (status & 0x40) = 0

    select *-- tranlog files (*.LDF)

    from sysfiles

    where (status & 0x40) <> 0

    as per BOL

    http://msdn2.microsoft.com/en-us/library/ms178009.aspx

    but also notes you should be using new system tables, eg

    select *-- data files (*.MDF)

    from sys.database_files

    where [type]=0

    select *-- tranlog files (*.LDF)

    from sys.database_files

    where [type]=1

    HTH

    Dick

  • Thank you!

  • If you're using SQL 2005, rather use the view sys.database_files. the statuses are given in text, no decoding necessary.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

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

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