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_’ + t.name + ‘ for [‘ + DB_NAME() + ‘].[‘ + s.name + ‘].[‘ + t.name + ‘]’
    from sys.tables t
        inner join sys.schemas s
            on t.schema_id = s.schema_id
    where t.type = ‘U’

image

I would like to have feedback from my blog readers.

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s