Thursday, July 08, 2010

How to: Drop a Database if it exists

Here is the T-SQL code for checking to create if the database exists. This code below drops the database and creates new.

-- Changed database context to 'master'
USE master
GO
-- Check Exists
IF EXISTS(SELECT name FROM sys.databases
WHERE name = 'Angel83')
DROP DATABASE Angel83
GO
-- Create Database
CREATE DATABASE Angel83
GO

No comments:

Post a Comment