instance alias

  • Is there a way to alias an instance within a stored procedure? Such as:

    [server2].GEMedical.dbo.TableName

    I am running sql 2000 and 2008 side by side on a single server, and thus [server2] is a linked server connection to access a db and table in the 2000 instance from within sql 2008. Ideally, I would like to pass in everything to the left of TableName, or at least use an alias.

  • You can create a SYNONYM for that object - as in:

    CREATE SYNONYM dbo.MyTableName FOR [linked server].db.dbo.TableName;

    Then, in your code you reference your synonym:

    SELECT {columns} FROM dbo.MyTableName;

    If the linked server changes, or the database is moved to the local instance, you just drop the synonym and recreate it with the new values.

    Of course, if you want something that is dynamically defined by a parameter or something like that then you need use dynamic SQL.

    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

Viewing 2 posts - 1 through 1 (of 1 total)

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