When my colleague drops a database he just created on SQL 2008 Express using Management Studio 2008 the files do not get deleted.

When I drop a database I just created on SQL 2005 Express using Management Studio 2008 the files do get deleted.

If my uninstaller executes a DROP DATABASE query on the same 2005 database then the files do not get deleted.

Is there a setting that determines if files will be deleted or what is going on?

  • yes! this is a feature!! – Nick Kavadias Jan 11 '10 at 15:03

How does your colleague drop the database? If he is detaching them, then they won't get deleted - perhaps he's doing that? Alternatively, if the database is offline when it's deleted then the data files do not get deleted. See DROP DATABASE for more information on this.

  • 1
    This makes sense as my uninstaller's query to drop the database looks like this: "ALTER DATABASE " + dbName + " SET OFFLINE WITH ROLLBACK IMMEDIATE; DROP DATABASE " + dbName; – Ries Jan 8 '10 at 10:19
  • 1
    So after kicking out all users by setting to offline, I should probably take it back online again before dropping it. – Ries Jan 8 '10 at 10:20
  • 1
    You could also use SET SINGLE_USER or RESTRICTED_USER so you don't have to take the database offline. – Mark Allison Jan 8 '10 at 11:04

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.