Check if table exists in MS SQL database

I needed to check if the tables are in the database or not. Here is an example of the SQL query – it returns 1 if one of the tables exists and 0 if they do not exist.


IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE 
	TABLE_NAME = 'RoleClaims' or TABLE_NAME = 'Users')
    SELECT 1
ELSE
    SELECT 0

You can use this code if you need to check if tables exist. For example, to create tables in case if nullable result

Leave a Reply

Your email address will not be published. Required fields are marked *