Sunday, March 11, 2012

DROP DATABASE Question

Hello,
in our project i have to drop an existing sql server database and
immediately create a new (and empty) one with exactly the same name. MSDN
says that in case of dropping a database also the physical files on the
harddrive are deleted but this is not the case, as sql server complains that
there's already a file with that name on disk.
Is there a way to delete also the disk files of a database using T-SQL or do
i have to choose a different approach?
Thanks in advance
ChristianIn 6.5 and older, the database files were not deleted when you execute DROP
DATABASE. As of 7.0,
they are. If you are seeing something different, you have either hit a bug i
n the product (unlikely)
or may have some problems in your scripts.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"chris" <chris@.discussions.microsoft.com> wrote in message
news:68AFCD1C-85B6-4661-9332-3F50830BF386@.microsoft.com...
> Hello,
> in our project i have to drop an existing sql server database and
> immediately create a new (and empty) one with exactly the same name. MSDN
> says that in case of dropping a database also the physical files on the
> harddrive are deleted but this is not the case, as sql server complains th
at
> there's already a file with that name on disk.
> Is there a way to delete also the disk files of a database using T-SQL or
do
> i have to choose a different approach?
> Thanks in advance
> Christian|||Check the default file location. Could it be that you previously created a
database with the same name in this location, but later abandoned it and
started creating databases with files in another location while the default
file location was left unchanged?
The easiest way would be to check your default location and check your file
system.
ML
http://milambda.blogspot.com/|||Thank you very much for your replies.
I found that before dropping the database it was set OFFLINE to disconnect
users and in this case the files remain on disk. I set it to SINGLE_USER
instead and then it worked.
Chris
"chris" wrote:

> Hello,
> in our project i have to drop an existing sql server database and
> immediately create a new (and empty) one with exactly the same name. MSDN
> says that in case of dropping a database also the physical files on the
> harddrive are deleted but this is not the case, as sql server complains th
at
> there's already a file with that name on disk.
> Is there a way to delete also the disk files of a database using T-SQL or
do
> i have to choose a different approach?
> Thanks in advance
> Christian|||> I found that before dropping the database it was set OFFLINE to disconnect
> users and in this case the files remain on disk.
That was news for me. Thanks for sharing the information, Chris.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"chris" <chris@.discussions.microsoft.com> wrote in message
news:B5951FCB-2434-4241-969C-02BF0E7816A3@.microsoft.com...
> Thank you very much for your replies.
> I found that before dropping the database it was set OFFLINE to disconnect
> users and in this case the files remain on disk. I set it to SINGLE_USER
> instead and then it worked.
> Chris
> "chris" wrote:
>

No comments:

Post a Comment