Prevent inserts to a non existing Synonym I have a Synonym called VirtualTable which points to RealTable1.

A lot of inserts are happening to VirtualTable - about 50 every second.

Very often I drop the synonym and re-create it to point to RealTable2.

Unfortunately it happens some times, that between the time I drop the synonym and recreate it, an insert is attempted against VirtualTable and I get an annoying but understandable error:

Invalid object name 'dbo.VirtualTable'

I tried dropping and creating the synonym in a transaction, but that doesn't make any difference. How can it encapsulate something that doesn't exist.

I know that I cannot rename or repoint a Synonym.

So my question is how I can make sure that inserts to VirtualTable are paused for the millisecond that it takes me to recreate the Synonym?

Or perhaps someone has a different idea of how to solve this.
Check if the synonym exists before the insert/update.

IF EXISTS (SELECT * FROM sys.synonyms
WHERE name = 'VirtualTable')
 PRINT 'do your stuff'