Check if a SQL DataBase Exist

Apart from firing a SELECT Query to determine whether or not a database, a datatable, or, a Stored Procedure we can use the following in-built function to do the same:

if db_id('dbname') is not null 
if object_id('object_name', 'U') is not null -- for table
if object_id('object_name', 'P') is not null -- for SP

Advertisements