Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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.)

share|improve this question

migrated from stackoverflow.com Nov 30 '12 at 11:21

This question came from our site for professional and enthusiast programmers.

    
Please consider: meta.stackexchange.com/questions/5234/… –  Nick Vaccaro Nov 29 '12 at 21:21
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
add comment

1 Answer

up vote 1 down vote accepted

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 .

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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