Find File Name of Database

  • Via T-SQL, how could I find the file name of the database (name.mdf).  I am particularly intersted in finding out whether it has the _Data suffix or not.  I need to do this programmatically.

    Thanks!

    MSSQL2000

  • Use master

    select name,filename from sysdatabases

  • I just realized that... how lame of me.

    I know it is not generally advisable to access the sys files directly.  Is this the case with this table as well?

    Thanks for the quick post!

  • I think you could access the sysfiles directly if what you mean by accessing is reading their content. Actually I would advice anyone to learn about them and use them as much as you can so you can better understand how the SQL Server works. The same goes for all the system SPs.

    What is not advisable is to 'mess' with the systables directly. Meaning updating them without the full understanding of what are you doing because you can screw up your database or even the whole server.

    ---------------------------------------------
    [font="Verdana"]Nothing is impossible.
    It is just a matter of time and money.[/font]

  • Just as a friendly reminder, you can also use the sp_helpdb stored procedure to see this data as well, plus a little more.

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

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