Not the most elegant of solutions, but you could join the sys.synonyms
table to the sys.tables
table to check whether the table exists.
If the table does not exist, the join will fail and you will get 0 rows (hence IF EXISTS
will be false). If the table does exist, the join will success and you will get 1 row (and true):
IF EXISTS( SELECT *
FROM sys.synonyms s
INNER JOIN sys.tables t ON REPLACE(REPLACE(s.base_object_name, '[', ''), ']', '') = t.name
WHERE s.name = 'TargetReportingTable')
BEGIN
-- Does exist
END
ELSE
BEGIN
-- Does not exist
END
Replace 'TargetReportingTable'
with whichever synonym you wish to check.