How to find the Database name from MDF or LDF files

Here is the query to find the Database name from MDF or LDF files:

select b.*, b.[name], b.database_id, a.physical_name
from sys.master_files a
inner join sys.databases b on a.database_id=b.database_id
where a.physical_name like ‘%<LDF or MDF file>%’

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: