I have a copy of the mdf and log files of a database. The database is a MSSQL 2012 database. To use it, I did the following steps (a bit by chance actually, because I was trying to copy a mdf and log file out of the data directory first, and it wouldn't let me while the server was using them):
- I stopped the MSSQL server process in Windows
- Copied them into the
DATA
directory. - Then I started the MSSQL servcer process again.
In SQL server management studio, the new database appeared. I thought I might have needed to attach it.
Does MSSQL server automatically attach all mdf's in the data directory? I'm worried it is not working as it should, even though it looks like it.
Best Answer
No it does not attach a new mdf and ldf automatically.
Instead of fiddling around with stopping sql service and copying around mdf and ldf files, I suggest you take a look at backup and restore commands.
-- now restore the database with move and recovery