All database physical_name Path

  • Hi,

    If i run this query i am getting physical_name and all the file details for particular database.

    SELECT * FROM [sys].[database_files]

    I want to know all the database physical path (.mdf and .ldf path) for a particular database server. Is it possible in sql server 2005.

    Appreciate for your help.

    ---

  • try this code to get the file paths for each db on a server.

    DROP TABLE #DBFiles

    CREATE TABLE #DBFiles

    (

    [DBName] [nvarchar](100),

    [Name] [nvarchar](100),

    [Filename] [nvarchar](100)

    )

    ON [PRIMARY]

    INSERT INTO

    #DBFiles

    EXEC sp_MSforeachdb 'Select ''?'' as DatabaseName, [?]..sysfiles.name,

    [?]..sysfiles.filename From [?]..sysfiles'

    SELECT

    *

    FROM

    #DBFiles

  • steveb (11/12/2008)


    try this code to get the file paths for each db on a server.

    DROP TABLE #DBFiles

    CREATE TABLE #DBFiles

    (

    [DBName] [nvarchar](100),

    [Name] [nvarchar](100),

    [Filename] [nvarchar](100)

    )

    ON [PRIMARY]

    INSERT INTO

    #DBFiles

    EXEC sp_MSforeachdb 'Select ''?'' as DatabaseName, [?]..sysfiles.name,

    [?]..sysfiles.filename From [?]..sysfiles'

    SELECT

    *

    FROM

    #DBFiles

    its really amazing steve.

    very gud

    kshitij kumar
    kshitij@krayknot.com
    www.krayknot.com

  • or simply:

    SELECT * FROM master.sys.master_files

    if you want that matched up to the database name

    select c.name,a.name as logicalname,a.physical_name from

    master.sys.master_files a

    inner join master.sys.sysdatabases c on a.database_id=c.dbid

    order by dbid

    ---------------------------------------------------------------------

  • Thanks You Very Much GUYZZZ...

    Great Work...! :w00t:

  • Please use following command :

    select db_name(dbid),filename from sys.sysaltfiles

    order by 1

    _____________________________________________________________________________________________________________
    Paresh Prajapati
    ➡ +919924626601
    http://paresh-sqldba.blogspot.com/[/url]
    LinkedIn | Tweet Me | FaceBook | Brijj

  • steveb (11/12/2008)


    try this code to get the file paths for each db on a server.

    DROP TABLE #DBFiles

    CREATE TABLE #DBFiles

    (

    [DBName] [nvarchar](100),

    [Name] [nvarchar](100),

    [Filename] [nvarchar](100)

    )

    ON [PRIMARY]

    INSERT INTO

    #DBFiles

    EXEC sp_MSforeachdb 'Select ''?'' as DatabaseName, [?]..sysfiles.name,

    [?]..sysfiles.filename From [?]..sysfiles'

    SELECT

    *

    FROM

    #DBFiles

    Hi steveb,

    I am not getting "sp_MSforeachdb" in Sql Server online help. Where shall i get the information for the same.

    ---

  • It's an undocumented stored procedure and does not appear in books on-line, am not sure why as i find it useful.

    try this link for help

    http://www.databasejournal.com/features/mssql/article.php/3441031/SQL-Server-Undocumented-Stored-Procedures-spMSforeachtable-and-spMSforeachdb.htm

Viewing 8 posts - 1 through 7 (of 7 total)

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