Unlike MySQL or PostgreSQL, SQL Server doesn’t have a native “CREATE TABLE IF NOT EXISTS” statement, but I’ll show you four simple methods that I’ve used successfully to achieve this.
Create Table If Not Exists SQL Server
Method-1: Using OBJECT_ID()
The OBJECT_ID function provides the most reliable and widely-supported method for checking table existence across all SQL Server versions.
Syntax
IF (OBJECT_ID('Table name') IS NOT NULL )
BEGIN
PRINT 'Table with the same name available'
END
ELSE
BEGIN
CREATE TABLE TableName (
Column1 datatype,
Column2 datatype,
Column3 datatype
);
ENDExample
We can execute the query below to create a brand new table SalesAz if doesn’t exist.
IF (OBJECT_ID('SalesAz') IS NOT NULL )
BEGIN
PRINT 'Table with the same name available'
END
ELSE
BEGIN
PRINT 'No Table available with this name. Let us create a new table'
CREATE TABLE SalesAz (
SalesID INT,
ProductName nVARCHAR(50),
ProductCategory nVARCHAR(50)
);
ENDAfter executing the above query, I got the expected output, and the SalesAz table was created successfully.

Now, let me rerun the same query. I received the expected output as “Table with the same name available.” Since the table already exists with the same name, please refer to the screenshot below for your reference.

Method-2: Using the INFORMATION_SCHEMA.TABLES
Syntax
IF EXISTS (SELECT 1
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'TableName')
BEGIN
print 'Table with the same name exists';
END
ELSE
BEGIN
CREATE TABLE TableName (
Column1 datatype,
Column2 datatype,
Column3 datatype
);
ENDExample
Here, we will execute the query below to verify if a table named ‘SalesNew’ exists. If not, it will create a new table with the same name.
IF EXISTS (SELECT 1
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'SalesNew')
BEGIN
print 'Table with the same name exists';
END
ELSE
BEGIN
PRINT 'No, Table not available. Let us create the table'
CREATE TABLE SalesNew (
ProductID INT,
ProductName nVARCHAR(50),
ProductBrand nVARCHAR(50)
);
print 'Table Created successfully';
ENDAfter executing the above query, I got the expected output, as shown below.


Method-3 Using the sysobjects
Syntax
IF EXISTS (SELECT 1
FROM sysobjects
WHERE name = 'TableName' AND xtype = 'U')
BEGIN
print 'Table with the same name exists';
END
ELSE
BEGIN
PRINT 'No, Table not available. Let us create the table'
CREATE TABLE TableName (
column1 datatype,
column2 datatype,
column3 datatype
);
print 'Table Created successfully';
ENDExample
I executed the query below, which created the AzureUSA table since it did not exist. The screenshot below is for your reference.
IF EXISTS (SELECT 1
FROM sysobjects
WHERE name = 'AzureUSA' AND xtype = 'U')
BEGIN
print 'Table with the same name exists';
END
ELSE
BEGIN
PRINT 'No, Table not available. Let us create the table'
CREATE TABLE AzureUSA (
ProductID INT,
ProductName nVARCHAR(50),
ProductBrand nVARCHAR(50)
);
print 'Table Created successfully';
ENDMethod-4: Using the sys.tables
Syntax
IF EXISTS (SELECT 1
FROM sys.tables
WHERE name = 'Your table name' AND schema_id = SCHEMA_ID('dbo'))
BEGIN
print 'Yes !! Table exists';
END
ELSE
BEGIN
PRINT 'No, Table not available. Let us create the table'
CREATE TABLE TableName (
column1 datatype,
column2 datatype,
column3 datatype
);
print 'Table Created successfully';
ENDExample
We can execute the query below to create the CustomerActivities table.
IF EXISTS (SELECT 1
FROM sys.tables
WHERE name = 'CustomerActivities' AND schema_id = SCHEMA_ID('dbo'))
BEGIN
print 'Table with the same name exists';
END
ELSE
BEGIN
PRINT 'No, Table not available. Let us create the table'
CREATE TABLE CustomerActivities (
CustomerID INT,
CusterName nVARCHAR(50),
Desg nVARCHAR(50)
);
print 'Table Created successfully';
ENDAfter executing the above query, I got the expected output, as shown below.


Conclusion
The “create table if not exists” pattern is essential for building reliable, maintainable SQL Server applications. The methods I’ve shared in this comprehensive guide—from the reliable OBJECT_ID function to advanced dynamic SQL implementations—represent well-tested approaches that I’ve successfully used.
You may also like the following articles:
- SQL Server Create Table With Primary Key
- How to Drop Table If Exists in SQL Server
- How to Insert into Table from Stored Procedure with Parameters
- How to Retrieve Data from Temp Table in SQL Server
After working for more than 15 years in the Software field, especially in Microsoft technologies, I have decided to share my expert knowledge of SQL Server. Check out all the SQL Server and related database tutorials I have shared here. Most of the readers are from countries like the United States of America, the United Kingdom, New Zealand, Australia, Canada, etc. I am also a Microsoft MVP. Check out more here.