Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Creating a Synonym for a Table - SQL School Video Expand / Collapse
Author
Message
Posted Wednesday, November 26, 2008 1:52 PM
SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: Moderators
Last Login: Wednesday, June 4, 2014 12:29 PM
Points: 1,931, Visits: 234
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
Post #609424
Posted Tuesday, January 20, 2009 4:55 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, March 8, 2013 10:18 AM
Points: 47, 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
Post #639808
Posted Tuesday, January 20, 2009 7:06 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Saturday, September 28, 2013 11:55 AM
Points: 164, 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. :)
Post #639927
Posted Tuesday, January 20, 2009 8:13 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, October 21, 2013 10:48 AM
Points: 966, Visits: 933
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.



Post #639960
Posted Tuesday, January 20, 2009 5:15 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 1:03 PM
Points: 4,388, Visits: 9,510
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 opportunites brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs
Post #640317
Posted Wednesday, January 21, 2009 1:39 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, July 17, 2014 10:36 PM
Points: 5,303, Visits: 1,378
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



Post #640484
Posted Wednesday, January 21, 2009 6:27 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, October 21, 2013 10:48 AM
Points: 966, Visits: 933
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.



Post #640638
Posted Wednesday, January 21, 2009 9:01 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, March 8, 2013 10:18 AM
Points: 47, 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
Post #640847
Posted Wednesday, January 21, 2009 9:10 AM


SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Monday, October 21, 2013 10:48 AM
Points: 966, Visits: 933
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.



Post #640856
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse