Home > SQL > SQL – Check If A Table Exists

SQL – Check If A Table Exists

Check if a table exists in a database:

IF OBJECT_ID(‘database.dbo.table’) > 0
BEGIN
   //Code to run if table exists. e.g. delete table.
   //drop table database.dbo.table
END

 

 

Advertisement
Categories: SQL Tags: , , , ,
  1. No comments yet.
  1. No trackbacks yet.

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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.