a simple question how to drop a database with the use of IF stmt to check if the object exist.
if object_id('dbo.myDB') is not null
drop database 'myDB'
go
the code returns no error but it also wont delete the database("myDB")
Printable View
a simple question how to drop a database with the use of IF stmt to check if the object exist.
if object_id('dbo.myDB') is not null
drop database 'myDB'
go
the code returns no error but it also wont delete the database("myDB")
You DROP tables, not databases.
To remove a database from disk use DELETE DATABASE dbname
hi hack there was an error return when i execute the script
http://images.cjb.net/0cdda.gif
Try this:
vb Code:
USE [master] GO IF EXISTS (SELECT name FROM sys.databases WHERE name = N'DBName') DROP DATABASE [DBName]
Edit: All I did was right click on the Database ---> Script Database as ---> Drop To ---> Clipboard.
why im getting this error:
Msg 3702, Level 16, State 4, Line 4
Cannot drop database "DBname" because it is currently in use.
the database was not in use/design mode/open by any application
Quote:
Originally Posted by jlbantang
Check the Activity Monitor and make sure that there aren't any connections to the database. If not, then depending upon your setup you may have to stop and then restart SQL Server.
sweet!
thnx!