I just right-click deleted all my databases that were not in use. However all the MDF and LDF files are still in the data folder on the machine. What is the best way to determine what MDF and LDF files I can remove since the database no longer exists in SSMS.

Also is this the best way to delete unused databases? (The right-click -> Delete method.)

  • 2
    assuming sql server's still running, any mdf/ldf which corresponds to a "live" database would be in use and would not let you delete it. – Marc B Nov 29 '12 at 21:23
  • Norla, I was unaware of that option. Thank you for pointing that out to me. I updated my past questions. Most answers are answered through these comments though so I cannot accept them. – Cole Mietzner Nov 29 '12 at 21:34

The Best way to delete databases in sql server is using DROP DATABASE command . If you right click and delete in SSMS you will end up with files left in folder .

Then You have to manually remove the files from server folder .

To remove these files from folder , first bring sql server to online then go the folder and start deleting the files , when deleting mdf or ldf files you will get error like files in use means that database you are using and you can remove remaining .

  • That worked perfect. I just selected everything and deleted it and windows allowed me to skip the files that were in use... Scary yes, but it worked. – Cole Mietzner Nov 29 '12 at 22:46
  • I think one danger with this technique is if auto-close is enabled on any databases, you could probably delete an mdf that is still attached. Haven't tried it though. – SqlACID Nov 30 '12 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.