---
title: "How to check table exists in SQL Server?"  
description: "How to check table exists in SQL Server?"  
author: "Revati S Misra"  
published: 2023-07-11  
updated: 2023-07-12  
canonical: https://www.mindstick.com/forum/159027/how-to-check-table-exists-in-sql-server  
category: "mssql server"  
tags: ["mssql server", "sql server", "sql"]  
reading_time: 2 minutes  

---

# How to check table exists in SQL Server?

How to [check](https://yourviews.mindstick.com/story/2248/never-forget-to-check-these-specifications-before-buying-a-mobile-phone) [table](https://www.mindstick.com/articles/43918/how-to-design-table-using-bootstrap) [exists in SQL](https://www.mindstick.com/forum/34362/how-to-check-if-a-column-exists-in-sql-server-table) [Server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over)?

## Replies

### Reply by Aryan Kumar

Sure, I can help you with that. Here are two ways 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) in [SQL Server](https://www.mindstick.com/articles/12999/what-is-table-valued-function-in-sql-server):

- **Using the** `IF EXISTS` **clause**

The `IF EXISTS` clause is a conditional statement that can be used to check if a table exists. The syntax for the `IF EXISTS` clause is as follows:

SQL

```plaintext
IF EXISTS (
    SELECT *
    FROM sys.tables
    WHERE name = 'table_name'
)
BEGIN
    -- Code to execute if the table exists
END;
```

The `table_name` is the name of the table that you want to check if it exists.

For example, the following code will check if the `Customers` table exists:

SQL

```plaintext
IF EXISTS (
    SELECT *
    FROM sys.tables
    WHERE name = 'Customers'
)
BEGIN
    PRINT 'The Customers table exists.';
END;
```

- **Using the** `OBJECT_ID()` **function**

The `OBJECT_ID()` function can be used to get the object ID of a table. If the table does not exist, the `OBJECT_ID()` function will return `NULL`.

The syntax for the `OBJECT_ID()` function is as follows:

SQL

```plaintext
SELECT OBJECT_ID('table_name');
```

The `table_name` is the name of the table that you want to get the object ID for.

For example, the following code will check if the `Customers` table exists:

SQL

```plaintext
DECLARE @table_id INT;

SET @table_id = OBJECT_ID('Customers');

IF @table_id IS NOT NULL
BEGIN
    PRINT 'The Customers table exists.';
END;
```


---

Original Source: https://www.mindstick.com/forum/159027/how-to-check-table-exists-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
