I need a T-SQL query for a list of all databases in SQL Server 2008 showing
.mdf
and .ldf
files.Default Location of MDF File in SQL Server Files that are common and used by all instances on a single system are installed inside the folder :\Program Files\Microsoft SQL Server\nnn\.
The msdb database file (msdb. mdf) and msdb log files (msdb. ldf) are located in the Program Files\Microsoft SQL Server\Mssql\Data directory. Due to the amount of configuration information stored in the msdb database, the database should be routinely backed up.
Launch SSMS -> Connect to the SQL Server instance -> Right-click on Database -> Click Attach. In the new Locate Database Files window, browse the file system to locate the MDF file. Double-click it. The associated data files and log files are populated in the associated files grid view in the Attach Databases window.
SELECT db.name AS DBName, type_desc AS FileType, Physical_Name AS Location FROM sys.master_files mf INNER JOIN sys.databases db ON db.database_id = mf.database_id
select d.name as 'database', mdf.physical_name as 'mdf_file', ldf.physical_name as 'log_file' from sys.databases d inner join sys.master_files mdf on d.database_id = mdf.database_id and mdf.[type] = 0 inner join sys.master_files ldf on d.database_id = ldf.database_id and ldf.[type] = 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With