50% OFF!!!

Thursday, June 11, 2009

Sql Server | Check if exist: DataBase, Table or Stored-Procedure

Here is a code for checking if an object exist in SQL SERVER.
This may be helpful if you have 2 enviroments and on each one of them
the object (db, table, stored-procedure) are diffrent,
so you can check whether this is the specific db and perform actions...

Check is Database exists:

if db_id('dbname') is not null



Check is Table exists:

if object_id('object_name', 'U') is not null -- for table



Check is Store-Procedure exists:

if object_id('object_name', 'P') is not null -- for SP



hope this is helps...

No comments:

Post a Comment