I have a utility database (customers) on my db server where I store all of the routines used to modify data on the other databases. We recently found out that using synonyms will greatly benefit us.
use Customers
IF EXISTS (SELECT * FROM employees.sys.synonyms WHERE name = 'tblPerson2') begin
drop synonym [dbo].tblPerson2
end
This doesn’t work because I am using the Customers database but need to drop the synonym from my employees database.
SQL Server 2008 doesn’t support this syntax –
drop synonym [employees].[dbo].tblPerson2
Anyone have any ideas on how to modify synonyms accross databases. My solution involves having to add an identical stored procedure to every database, which seems prone to error.
1 Answer