3

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?

Ries
  • 153
  • 1
  • 2
  • 6

1 Answers1

8

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.

Mark Allison
  • 2,188
  • 7
  • 26
  • 45
  • 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 08 '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 08 '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 08 '10 at 11:04