Database alias | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Database alias

Hi, Is it possible to create an alias for a database and refer this alias name in your queries ? For example, I have a database called ‘database1’ with a table name ‘table1’. I want to create an alias called ‘db1’ for the database and when I try to select from db1..table1, it should get me that data from database1..table1. How can I do this ?
I haven’t seen any such reference to alias the database, rather only to server or table. _________
Satya SKJ
Moderator
SQL-Server-Performance.Com

Thanks Satya, I thought so. But, wouldn’t it be good to have such an option ? For example, I have databases with same structure but with different names under different servers (viz. prod, test, dev etc.) and I want to write a distributed query that works on each of these servers without making any changes to the code.
True, but in the same case you would comment or echo in the code before executing on such environments.
_________
Satya SKJ
Moderator
SQL-Server-Performance.Com

]]>