Get File Names and Path

  • I have a sp that will accept a database name as a variable. I need to use that name to get the .mdf and .ldf file names and paths for that database.

    Does anyone have a solution for this?

    I will then use those filenames and paths to perform a detach and subsequent attach of the database.

    Thanks.

    Paul

  • Look up sysfiles system table in BOL.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • What is BOL?

    Will that get around creating dynamic sql based on the database name passed in to the sp?

    Thanks,

    Paul

  • Books On-Line (SQL Server Help files).  Yes, you will be able to use the sysfiles table in dynamic SQL.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • You can get the file name from the SYSdatabases table in master...

    USE MASTER

    SELECT filename FROM sysdatabases

    WHERE name = 'pubs'

    returns....

    filename

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

    c:\sql\data\MSSQL\data\pubs.mdf

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

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