SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating a Synonym for a Table - SQL School Video


Creating a Synonym for a Table - SQL School Video

Author
Message
Brian Knight
Brian Knight
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: Moderators
Points: 2655 Visits: 235
Comments posted to this topic are about the item Creating a Synonym for a Table - SQL School Video

Brian Knight
Free SQL Server Training Webinars
fuller.artful
fuller.artful
SSC Journeyman
SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)

Group: General Forum Members
Points: 83 Visits: 165
You described well the "how to" aspect of synonyms, but what I fail to grasp its the usefulness. Why would I want to create a synonym? What advantage is gained? By your example, I even have to type an extra keystroke ("1" or "2") when referring to the "Contact" table.

Thanks,
Arthur

Arthur Fuller
cell: 647-710-1314

Only two businesses refer to their clients as users: drug-dealing and software development.
-- Arthur Fuller
chris.schau
chris.schau
SSC-Enthusiastic
SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)SSC-Enthusiastic (176 reputation)

Group: General Forum Members
Points: 176 Visits: 262
The usefulness of synonyms has do to with changing database object locations/names without changing application code. For instance if your application is coded to read from the Orders table and for some reason you have to point it at a copy of the Orders table on a different server you can create a synonym rather than changing your application code...or you can just change your app code. Smile
ChrisMoix-87856
ChrisMoix-87856
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1214 Visits: 941
I really wish you could use synonyms for databases on remote servers. We use SQL Client Aliases to keep from having to change code going from development , to QA, to Production. The only problem is that those are set on a server level. With clusters, that's one more thing to manage.

It would be nice to use synonyms to abstract the database call instead of having to resort to Client Aliases and Linked Servers.



Jeffrey Williams 3188
Jeffrey Williams 3188
SSCertifiable
SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)SSCertifiable (8K reputation)

Group: General Forum Members
Points: 7983 Visits: 9971
ChrisMoix (1/20/2009)
I really wish you could use synonyms for databases on remote servers. We use SQL Client Aliases to keep from having to change code going from development , to QA, to Production. The only problem is that those are set on a server level. With clusters, that's one more thing to manage.

It would be nice to use synonyms to abstract the database call instead of having to resort to Client Aliases and Linked Servers.


Not sure what you are referencing here, but you can easily create a synonym that accesses an object through a linked server.

Create the linked server, then in the local database create the synonym as:

CREATE SYNONYM MySchema.Object FOR linkedserver.remotedb.schema.object;

Now, when your code is moved from DEV to QA to PROD - it doesn't have to change. The synonyms on each system are setup to access the appropriate server and objects.

Jeffrey Williams
Problems are opportunities brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs

Anipaul
Anipaul
SSCertifiable
SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)SSCertifiable (7.4K reputation)

Group: General Forum Members
Points: 7423 Visits: 1407
fuller.artful (1/20/2009)
You described well the "how to" aspect of synonyms, but what I fail to grasp its the usefulness. Why would I want to create a synonym? What advantage is gained? By your example, I even have to type an extra keystroke ("1" or "2") when referring to the "Contact" table.

Thanks,
Arthur


This link can answer your query:
http://www.mssqltips.com/tip.asp?tip=1076



ChrisMoix-87856
ChrisMoix-87856
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1214 Visits: 941
Not sure what you are referencing here, but you can easily create a synonym that accesses an object through a linked server.

Create the linked server, then in the local database create the synonym as:

CREATE SYNONYM MySchema.Object FOR linkedserver.remotedb.schema.object;


I basically want a synonym on a whole database, not an object at a time. Currently I have to use a combination of a Client Network Alias and a Linked Server to accomplish this;

For example - Server 1 needs to query Northwind on Server 2. On server 1:
Create a Client Network Alias named NorthwindAlias and point it to Server 2.
Create a Linked Server named NorthwindAlias and map logins.
Write a query referencing NorthwindAlias.dbo.xxxxx, etc.



fuller.artful
fuller.artful
SSC Journeyman
SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)SSC Journeyman (83 reputation)

Group: General Forum Members
Points: 83 Visits: 165
Thanks for the illumination. I have run into this problem several times (dev/qa/prod) and now I think I have a glimmer of how to solve this. Thanks!

Arthur

Arthur Fuller
cell: 647-710-1314

Only two businesses refer to their clients as users: drug-dealing and software development.
-- Arthur Fuller
ChrisMoix-87856
ChrisMoix-87856
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1214 Visits: 941
If my kludge helps, great!

I'd really like to be able to accomplish this trye of thing entirely inside SQL Server (like with a synonyn) instead of relying on having to go to the desktop and run the SQL Server Configuration Manager, etc.



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search