Check existing databases then create

— CHECK existing databases for existence.
if exists (select * from master..sysdatabases where name = ‘dbName’ )
drop database dbName
GO

create database dbName
on primary
(name = ‘dbName’, filename = ‘C:\data\dbName.mdf’),
log on (name = ‘dbNameLOG’, filename = ‘C:\data\dbName.ldf’)
GO

About Spradlike

Husband and father, epilepsy survivor, avid percussionist, technology enthusiast...insisting on the road less traveled.
This entry was posted in SQL, Tools and Tricks and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *