SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 how to know the .mdf file belongs to which databas
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

chanduraag
Starting Member

India
14 Posts

Posted - 04/26/2013 :  09:33:33  Show Profile  Reply with Quote
Hi All,

i would like to know ...how to find the .mdf file belongs to which database....i tried with
DBCC CheckPrimaryFile ('Path of Mdf File', 2)

but it's showing the below error
---------
Msg 5123, Level 16, State 20, Line 1
CREATE FILE encountered operating system error 32(The process cannot access the file because it is being used by another process.) while attempting to open or create the physical file 'F:\MSSQL2008\MSSQL$DEFAULT\Userdatabases\databasename.mdf'.
---------------
is this DBCC command is used for the already retired databases.please provide your valuable advices for this .


Thanks All in Advance

James K
Flowing Fount of Yak Knowledge

3589 Posts

Posted - 04/26/2013 :  10:06:40  Show Profile  Reply with Quote
SELECT *  FROM sys.master_files
Look for name and physical_name columns.
Go to Top of Page

chanduraag
Starting Member

India
14 Posts

Posted - 04/26/2013 :  10:19:24  Show Profile  Reply with Quote
thank you very much for the prompt response..
but it's giving the .mdf and .ldf files of all the databases in the server
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3589 Posts

Posted - 04/26/2013 :  10:49:19  Show Profile  Reply with Quote
You can use a where clause to limit it to one database, or list the name of the database for each so you know which file belongs to which database.
SELECT DB_NAME(database_id),*  FROM sys.master_files ;
SELECT *  FROM sys.master_files WHERE DB_NAME(database_id) = 'YourDatabaseName';
Go to Top of Page

chanduraag
Starting Member

India
14 Posts

Posted - 04/26/2013 :  11:12:02  Show Profile  Reply with Quote
i vill axplain my question what actually i would like to know.......i am having a .mdf set from this fileset i would like to know which database MDF file is this???(to which database it is mapped),
Even i don't want to use sp_helpfile it will gives the list of .mdf and .ldf files associated with a particular database.

........thankq
Go to Top of Page

jackv
Flowing Fount of Yak Knowledge

United Kingdom
2047 Posts

Posted - 04/27/2013 :  03:51:31  Show Profile  Visit jackv's Homepage  Reply with Quote
Are you saying that currently the MDF is not attached to the SQL Server instance?

Jack Vamvas
--------------------
http://www.sqlserver-dba.com
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17606 Posts

Posted - 04/27/2013 :  23:04:31  Show Profile  Reply with Quote

SELECT 	*
FROM 	sys.master_files
WHERE   physical_name like '%' + 'theMDFFileName'



KH
Time is always against us

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000