Skip to main content

How to check the existence of a SQL Server Database.

if DB_ID('YOUR_DATABASE_NAME') is not null
    begin
        print N'Database exists.';
    end;
else
    begin
        print N'Database does not exist.';
    end;