I have a list of table names and I want to check whether each one of them exists in database or not. I know how to check if a table exists, and I can union select expressions for each table name, but there must be an easier solution. This is my current code:
select 'TableName1', CASE
WHEN EXISTS(SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'TableName1') THEN 1
ELSE 0
end
union
select 'TableName2', CASE
WHEN EXISTS(SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = 'TableName2') THEN 1
ELSE 0
end
-- and so on