Creating a Synonym for a Table - SQL School Video

  • Comments posted to this topic are about the item Creating a Synonym for a Table - SQL School Video

  • 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

  • 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. 🙂

  • 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.

  • 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
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

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

  • 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

  • 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.

  • 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

  • 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.

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply