To check if a table exists in MSSQL you can use one of these two snippets.

Sample MSSQL using INFORMATION_SCHEMA

IF (EXISTS (SELECT TABLE_NAME  
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_NAME = 'tablename' 
                 AND TABLE_SCHEMA = 'dbo' ))
BEGIN
    -- do something
END

Sample MSSQL using OBJECT_ID

IF OBJECT_ID('tablename') is not null
BEGIN
    -- do something
END

One thought on “How to check if a table exists in MSSQL”

Leave a Reply