---
title: "SQL Server: Check if table exists"  
description: "SQL Server: Check if table exists"  
author: "Anonymous User"  
published: 2013-05-06  
updated: 2013-05-06  
canonical: https://www.mindstick.com/forum/817/sql-server-check-if-table-exists  
category: "mssql server"  
tags: ["mssql server"]  
reading_time: 2 minutes  

---

# SQL Server: Check if table exists

Hi!\
I would like this to be the ultimate [discussion](https://answers.mindstick.com/qa/44930/what-is-the-procedure-for-half-an-hour-discussion) on how to [check if](https://www.mindstick.com/forum/12878/how-to-check-if-an-asp-dot-net-file-upload-control-has-a-file-in-jquery) a [table exists in SQL](https://www.mindstick.com/forum/159027/how-to-check-table-exists-in-sql-server) Server 2000/2005 using SQL Statement.\
When you [Google](https://www.mindstick.com/articles/43833/google-lighthouse-and-how-is-it-changing-the-way-we-development-and-design-websites) for the answer, you get so many different answers. Is there an [official](https://answers.mindstick.com/qa/93540/is-kidszone-different-from-official-mindstick)/backward & [forward](https://www.mindstick.com/forum/33488/in-webview-disabling-uitoolbar-s-back-and-forward-butttons) compatible way of doing it?\
Here are two possible ways of doing it. Which is the [standard](https://www.mindstick.com/articles/23223/naming-convention-or-coding-standard)/best way of doing it?**\****First way:**\

```
IF EXISTS (SELECT 1            FROM INFORMATION_SCHEMA.TABLES            WHERE TABLE_TYPE='BASE TABLE'            AND TABLE_NAME='mytablename')    SELECT 1 AS res ELSE SELECT 0 AS res;
```

**Second way:**

```
IF OBJECT_ID (N'".$table_name."', N'U') IS NOT NULL    SELECT 1 AS res ELSE SELECT 0 AS res;MySQL provides a nice SHOW TABLES LIKE '%tablename%'; statement. I am looking for something similar.
```

\
Thanks !

## Replies

### Reply by AVADHESH PATEL

Hi Pravesh!\
For queries like this it is always best to use an INFORMATION_SCHEMA view. These views are (mostly) standard across many different databases and rarely change from version to version.\
**To check if a [table exists](https://www.mindstick.com/forum/468/what-is-the-way-for-finding-out-whether-a-table-exists-in-the-microsoft-access-database) use:**\

```
IF (EXISTS (SELECT *                  FROM INFORMATION_SCHEMA.TABLES                  WHERE TABLE_SCHEMA = 'TheSchema'                  AND  TABLE_NAME = 'TheTable'))BEGIN    --Do StuffEND
```


---

Original Source: https://www.mindstick.com/forum/817/sql-server-check-if-table-exists

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
