Home All Groups Group Topic Archive Search About
Author
8 Sep 2006 6:35 PM
ngorbunov via SQLMonster.com
Is there some sort of command that can tell me which mdf and ldf files are
associated to which databases?

Thanks,
Ninel

--
Message posted via http://www.sqlmonster.com

Author
8 Sep 2006 6:45 PM
Aaron Bertrand [SQL Server MVP]
SELECT filename, db_name(dbid)
FROM master..sysaltfiles
ORDER BY dbid;


"ngorbunov via SQLMonster.com" <u9125@uwe> wrote in message
news:65fefd3e38aeb@uwe...
Show quote
> Is there some sort of command that can tell me which mdf and ldf files are
> associated to which databases?
>
> Thanks,
> Ninel
>
> --
> Message posted via http://www.sqlmonster.com
>
Author
8 Sep 2006 6:46 PM
Stu
There may be an easier way to do this, but this will work:

CREATE TABLE #t (dbname sysname, filename sysname)

INSERT INTO #t (dbname, filename)
exec sp_msforeachdb 'USE ?; SELECT ''?'', filename from sysfiles'

SELECT *
FROM #t
ORDER BY dbname

DROP TABLE #t



ngorbunov via SQLMonster.com wrote:
Show quote
> Is there some sort of command that can tell me which mdf and ldf files are
> associated to which databases?
>
> Thanks,
> Ninel
>
> --
> Message posted via http://www.sqlmonster.com

AddThis Social Bookmark Button