Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to drop a database if it exists

Author  Topic 

MGA
Starting Member

28 Posts

Posted - 2010-05-28 : 04:21:42
How to check for the existence of a database and if it exists drop it
like that
if exists (drop database Dbname)

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-05-28 : 04:27:56
IF EXISTS( SELECT 1 FROM sys.databases WHERE name = 'dbname')
BEGIN
DROP DATABASE dbname
END

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-05-28 : 04:30:41
use master
go
if db_id('your_db_name') is not null
DROP DATABASE your_db_name


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -