Results 1 to 2 of 2

Thread: Database Alias

  1. #1
    Join Date
    May 2005

    Unanswered: Database Alias

    Is there any way in SQLServer (2000) to setup an alias to another SQLServer database?

    What I want/need to do is this:

    .i have a database for each project but many of the tables schemas/triggers/stored procedures/etc. are common so what I want to do is run one set scripts. I want to essentially set up a project structure so that all specific app databases also include some core stuff.

    .for example, consider a Users table (simple example). For two applications we have exactly the same users structure, sprocs, triggers, etc. but we have physically different data. I just want to run the same ddl.

    .but the users table has a log associated with it in an associated log database. The trigger (and some historical queries) refer to the explicit log database (App1Log.Users, for example).

    .what i'm figuring is that if i could set up an alias to the log database and have the sql code refer to that I'd be able to reuse all the code very neatly:

    set logDBAlias = 'App1Log'

    insert into logDBAlias.Users etc....

    .trouble is I cannot figure out how to alias the log database!

    Any ideas?

    Thank you.
    Last edited by jhml; 09-27-06 at 10:04.

  2. #2
    Join Date
    May 2004
    I don't think this is possible.

    In 2005 you can createa a synonym, but a synonym is an alias for an object in a database, not a database.

    From BOL:

    Synonyms can be created for the following types of objects:

    Assembly (CLR) Stored Procedure
    Assembly (CLR) Table-valued Function
    Assembly (CLR) Scalar Function
    Assembly Aggregate (CLR) Aggregate Functions
    Extended Stored Procedure
    SQL Scalar Function
    SQL Table-valued Function
    SQL Inline-table-valued Function
    SQL Stored Procedure
    Table (User-defined)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts