Generating dynamic Synonyms for your Database tables

Hi Folks,

Today I am posting a very useful query which is required when you want to make a dynamic script which will help you to create synonyms for all your tables within a database.Query is as follows,Run it on the required database.

select ‘create synonym syn_’ + + ‘ for [‘ + DB_NAME() + ‘].[‘ + + ‘].[‘ + + ‘]’
    from sys.tables t
        inner join sys.schemas s
            on t.schema_id = s.schema_id
    where t.type = ‘U’


I would like to have feedback from my blog readers.

Please post your feedback, question, or comments about this article.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s