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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s