-1

One of the MDF files for a SQL Server database inadvertently ended up with 2 primary files (1 database is pointing to 2 different MDF files). How can I remove the reference to one of these files, so that I may reattach my database and bring it online?

M.Clark
  • 57
  • 2
  • 7
  • Your question doesn't make a lot of sense. You can't just stop pointing to one of the data files. Honestly you should be using a backup instead of trying to attach a data file anyway. And how exactly does a database inadvertently get 2 data files? This is something that must be done explicitly. – Sean Lange Mar 25 '16 at 18:17
  • Right Click database,select properties,select files,select mdf not needed and click remove. – nobody Mar 25 '16 at 18:20
  • I wish it was that easy. The database has been taken offline and detached. I need to reattach the database. When I right click databases folder > attach > click add > browse to database (which is an MDF file). It loads 3 files down below. 2 of them are Data Files and 1 is a log file - it doesn't give me the option to remove any of these. When I click OK, I get an error message that the 2 Data file are both primary files, and a database can only have 1 primary file. – M.Clark Mar 25 '16 at 18:31
  • MDF files contain data, so you can't just remove one. You can migrate the data from one to another, though. What you will have to do is bring the DB online and combine the files into one. http://www.sqldbpros.com/2010/12/sql-server-combine-mdf-files-the-easy-way/ – JLB Mar 25 '16 at 18:37

1 Answers1

0

I realized that we had Sandbox environments cloned from all of our production stuff that was about 1 month old. Luckily, that particular database is not used very often and had not been written to in over a month. So I was able to capture a BAK file from the Sandbox environment, and restore the database to our production environment. Worked like a charm!

M.Clark
  • 57
  • 2
  • 7