To attach a database using SSMS, first, open SSMS connect to the database engine Right-click on “databases” select “Attach.” See the following image: We can attach the SQL Server database files using the following methods: In “Path” and “File Name” columns show the location of the database files. To view the database files location using SQL Server management studio, open SSMS Connect the database engine Expand databases right-click on “ WideWorldImportors” Select properties. Select db_name ( ) as, type_desc as, physical_name as from sys. Now to obtain the location of database files from sys.master_files DMV, execute the following query. The difference is between sys.master_files provides the physical location of all the databases and sys.database_files provides the information of the specific database.įor the demonstration, I have restored the “ WideWorldImportors” demo database. We can obtain the location of the database files by querying sys.database_files and sys.master_files dynamic management views.
#YOUTUBE USING SQL BACKUP MASTER HOW TO#
How to find the location of the MDF files LDF file has all the information that can be used to recover a database. It stores the changes made in the database by insert, update, delete, etc. For example, if you want to keep the tables on X drive and indexes on Y drive, then you can keep the tables on the primary data file and indexes on the secondary data file. Secondary data files are useful when we want to stripe the data across multiple drives of the database server. The purpose of the primary data file and secondary data file (.ndf file) are the same.
It also contains the vital information of the database. The primary data file contains columns, fields, rows, indexes, tables, and data added by an application. You can use another extension (*.gbn) to create a primary database file without any error. mdf is a preferred extension of the primary database file. The SQL Server database stores data in MDF files. First, let me explain about the database files.Ī SQL Server database has three types of files: This article demonstrates different methods to attach SQL Server MDF files.