How to check if a Table exists in SQL Server or not with an example? It is one of the Frequently Asked Questions.
How to Check if a Table exists in SQL Server?
In this example, we show you how to check whether a table exists or not using the OBJECT_ID. Here we used the IF ELSE statement to print different outputs (Message) based on the condition result.
-- Query:- check table exists before creating
IF OBJECT_ID('dbo.Employees', 'U') IS NOT NULL
BEGIN
PRINT 'Table Exists in SQL Test Database'
END
ELSE
BEGIN
PRINT 'Table Does not Exists'
END
TIP: Before you start SQL CREATE TABLE, it is always advisable to check if a SQL Server Table exists or not using SQL IF ELSE.

Check if a Table exists or Not using Information_schema.tables
In this example, we are using the Information_schema.tables to check whether a table exists or not
Here, we used the SQL EXISTS operator to check whether the table Employees was present in the database or not. And if it is true, then it will return the first PRINT statement. Otherwise, it returns the statement inside the ELSE block.
IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = N'Employees')
BEGIN
PRINT 'Table Exists in SQL Test Database'
END
ELSE
BEGIN
PRINT 'Table Does not Exists'
END

Let me show you, what is the list of columns present in the INFORMATION_SCHEMA.TABLES
SELECT * FROM INFORMATION_SCHEMA.TABLES

Now, let me try with the table that doesn’t exist.

Check if a Table exists or not using SQL Server sys.Objects
Here, we check whether a table exists in the Server or not using the sys.Objects.
-- SQL check if table exists before creating
IF EXISTS(SELECT 1 FROM sys.Objects
WHERE Object_id = OBJECT_ID(N'dbo.Employees')
AND Type = N'U')
BEGIN
PRINT 'Table Exists in SQL Test Database'
END
ELSE
BEGIN
PRINT 'Table Does not Exists'
END

Let me show you the list of available columns in the sys.Objects. Here type = U means User tables.
-- SQL check if table exists before creating SELECT * FROM sys.Objects WHERE TYPE = N'U'

Using sys.Tables
In this example, we will show how to check whether a table exists or not using the sys.Tables. Please refer to the Get Table Names from the Database and Get Column Names from Table articles.
IF EXISTS(SELECT 1 FROM sys.Tables
WHERE Name = N'Employees')
BEGIN
PRINT 'Table Exists in SQL Test Database'
END
ELSE
BEGIN
PRINT 'Table Does not Exists'
END

Let me show you the list of available columns present in the sys.Tables.
SELECT * FROM sys.Tables
