IF NOT EXISTS ( SELECT * FROM sys.databases WHERE name = N'myDB' ) CREATE DATABASE myDB ON PRIMARY (FILENAME = 'C:\path\myDB.MDF') FOR ATTACH GO