How to View SQL Server Database File Locations

Native Solution vs. Netwrix Auditor for SQL Server
{{ firstError }}
We care about security of your data. Privacy Policy
Native Solution Netwrix Auditor for SQL Server
Native Solution
Netwrix Auditor for SQL Server
  1. Start Microsoft SQL Server Management Studio (MSSMS).
  2. On the File menu, clickConnect Object Explorer. In the Connect to Server dialog box:
  • In the Server type list box, selectDatabase Engine.
  • In the Server name text box, type the name of the SQL cluster server.
  • In the Authentication list box, choose your SQL Server Authentication method and specify the user credentials. If you do not want to re-type the password every time you connect to the server, tick Remember password.
  1. Click Connect.
  2. Upon connection, click “New Query” and paste the following script into the query field:



    mdf.physical_name as data_file, 

    ldf.physical_name as log_file, 

    db_size = CAST((mdf.size * 8.0)/1024 AS DECIMAL(8,2)), 

    log_size = CAST((ldf.size * 8.0 / 1024) AS DECIMAL(8,2))

FROM (SELECT * FROM sys.master_files WHERE type_desc = 'ROWS' ) mdf

JOIN (SELECT * FROM sys.master_files WHERE type_desc = 'LOG' ) ldf

ON mdf.database_id = ldf.database_id

  1. Click Execute (or hit the F5 key).
  2. Review the list of SQL database locations in the query execution results:


  1. Open Netwrix Auditor and navigate to Reports -> Predefined -> SQL Server - State-in-Time -> SQL Server Databases.
  2. Click View.

Get Detailed SQL Server Database File Location Information in a Few Clicks

Microsoft SQL Server has become one of the most popular relational database management systems for small and large businesses alike. IT pros need to be able to say exactly where important SQL database file locations are stored without delays or errors for multiple reasons, such as to facilitate backups and recovery processes, transfer files to another location, or find the folder if a server instance was installed in a non-standard location. 

SQL Server stores data using two file extensions: 

  • MDF files are data files that hold data and objects such as tables, indexes, stored procedures, and views.
  • LDF files are the transaction log files that record all transactions and the database modifications made by each transaction.

The default SQL server data file location path depends on the version of the Microsoft SQL Server software:

  • SQL Server 2017 —C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\
  • SQL Server 2019 — C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DATA\
  • SQL Server 2022 — C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA\

You have two native options for finding out where the SQL server stores its database files: either right-click on the instance name in SQL Server Management Studio (SSMS) and navigate to the ‘Database Settings’ tab or use a T-SQL query. SSMS allows you to check one database at a time, and queries require some expertise and time to compose.

With Netwrix Auditor for SQL Server, you can get a comprehensive report on SQL Server database file locations that includes a summary of all key settings in just a few clicks. You can also report and alert on configuration changes, such as modifications to important functions, schemas, functions, database options, and object owners. Even better, Netwrix Auditor also provides deep visibility into permissions to your SQL instances, databases and other SQL objects, as well as reporting and alerting on changes to those permissions. With this powerful tool, you can spot and revert improper or malicious changes to configurations and permissions before they lead to downtime or a data breach.

Related How-tos