Code that tests whether a database exists before it deletes it : DROP DATABASE « Data Convert Functions « SQL Server / T-SQL Tutorial






4>
5> IF DB_ID('TestDB') IS NOT NULL
6>     DROP DATABASE TestDB
7> GO
1>
2> CREATE DATABASE TestDB
3> GO
1>
2> create table Billings (
3>     BankerID           INTEGER,
4>     BillingNumber      INTEGER,
5>     BillingDate        datetime,
6>     BillingTotal       INTEGER,
7>     TermsID            INTEGER,
8>     BillingDueDate     datetime ,
9>     PaymentTotal       INTEGER,
10>     CreditTotal        INTEGER
11>
12> );
13> GO
1>
2>
3> IF OBJECT_ID('Billing') IS NOT NULL
4>     DROP TABLE Billing
5> GO
1>
2> DROP DATABASE TestDB;
3> GO








13.4.DROP DATABASE
13.4.1.The DROP Database Statement
13.4.2.Code that tests whether a database exists before it deletes it