MSSQLTips.com - your daily source for SQL Server tips

Google
 
Web mssqltips.com

ESSENTIALS: Home | Tips | Search | Categories | Top 10 | Products | Authors | Blogs | Forums | Webcasts | Advertise | About
master.dbo.sysdatabases - MSSQLTips

MSSQLTips

MSSQLTips.com - your daily source for SQL Server tips
Welcome to MSSQLTips Sign in | Join | Help
in Search

master.dbo.sysdatabases

Last post 12-20-2007 11:14 AM by aprato. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 12-20-2007 8:52 AM

    • BrianB
    • Top 500 Contributor
    • Joined on 12-20-2007
    • Posts 1

    master.dbo.sysdatabases

    In SQL 2000 you could use this statement to get the path to a database file

    SELECT Filename FROM master.dbo.sysdatabases WHERE Name = 'MyDatabase'

    but this won't return anything in SQL 2005.  Any ideas how to retrieve the path to the database from any other SQL queries??

    I've seen other links where they discuss the conversion from 2000 to 2005 and using "sys.databases" in place of "master.dbo.sysdatabases" but it doesn't contain the field 'Filename' which is the one I am after.  Any help would be greatly appreciated.

     Thanks,

    BrianB

  • 12-20-2007 11:14 AM In reply to

    • aprato
    • Top 10 Contributor
    • Joined on 12-01-2007
    • Greater Boston
    • Posts 262

    Re: master.dbo.sysdatabases

     Hi Brian

     

    You can get this information in SQL 2005 from table sys.master_files


    select physical_name
    from sys.master_files
    where database_id = db_id('<my database>') and [file_id] = 1 
     

    - Armando 

Page 1 of 1 (2 items)