Hi guys I got a huge problem. One of my employes deleted a MSSQL Database instead of detach. Now i tried to recover the .mdf and .ldf file but when i trie to attach it it says. "File is not a primary database file" Anybody got an Idea how to fix this? It's very urgent.
Right click on the database name. Select Tasks -> Shrink -> Database Then click OK! I usually open the Windows Explorer directory containing the database files so I can immediately see the effect. I was actually quite surprised this worked! Normally I've used DBCC before, but I just tried that and it didn't shrink anything so I tried the GUI (2005) and it worked great - freeing up 17Gb in 10 seconds Edit: In Full recovery mode this might not work, so you have to either back up the log first, or change to Simple recovery, then shrink the file. ps: Use MDF Viewer Tool from http://www.mdf.viewertool.com/
Try using this.. CREATE DATABASE DatabaseName ON (FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\DatabaseName.mdf') FOR ATTACH_REBUILD_LOG; For more info visit. http://blog.sqlauthority.com/2010/04/26/sql-server-attach-mdf-file-without-ldf-file-in-database/