laredotornado wrote:
> Hi,
>
> I'm using MS Sql 2005. When I run a query from within "MyDatabase"
> that accesses another database, "OtherDatabase", is there a way I can
> create an alias, "OtherDatabaseOtherName", to access "OtherDatabase"
> so that I could run
>
> select * FROM OtherDatabaseOtherName.mytable
>
> and would mean the same thing as
>
> select * FROM OtherDatabase.mytable
>
> ? Thanks, - Dave
Just to add:
if the reason for this is you need to move the code from one environment to
another (perhaps a dev server to a production server) without modifying the
code, you can use synonyms. The result will not be two-part names: you can
create synonyms to point to objects in a database, not the database itself.
So instead of
OtherDatabase..mytable1, OtherDatabase..mytable2, you will have:
OtherDatabasemytable1, OtherDatabasemytable2
The definition of the synonyms can be different. For example, in the dev
MyDatabase, OtherDatabasemytable1 and point at a table in OtherDatabaseDev,
and in the prod MyDatabase, it can point at the table in OtherDatabaseProd.
>> Stay informed about: Way to alias a database?