Drop and Recreate Synonyms

This script is useful to script out all synonyms on a database before restoring on top another copy from another environment.

It is also useful to script out what's there, examine it, and see if any modifications are needed. See this one to verify synonyms

Rememer to change the output to "results to text".

 

SET NOCOUNT ON
SELECT
'IF EXISTS (SELECT NAME FROM SYS.OBJECTS WHERE NAME = '''+NAME+''')
DROP SYNONYM ['+NAME+'];
CREATE SYNONYM ['+NAME+'] FOR '+BASE_OBJECT_NAME+'

'
FROM sys.synonyms


Leave a Reply

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