We help IT Professionals succeed at work.

Is there a way to create an alias in a server for the databases within?

andersonpower
on
We have applications that whenever they are upgraded need to have a new database created and the new version points at it.  The problem is I have many queries that are pulling data across several databases, so when the DB get moved to new version all those queries have to be updated to the new database name.

Is it possible to create an alias for a database name that could be used on those queries and then just update the alias when the upgrade is done and not have to update the queries?
Comment
Watch Question

Brian CroweDatabase Engineer
Top Expert 2005
Commented:
Other than changing all of your cross-database queries to use dynamic sql there is no way to parameterize the target database.  Without knowing anything about your environment, I would question your need to rename the database with each version.

You could write a query to update the text of any queries that used the "old" database to the "new" database but that would require some careful scripting and testing.
Senior DBA
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
If you're going to rename db(s) across releases, I'd suggest always using dynamic SQL.  Then the current db names, and other names if needed, can be pulled from a control table.
Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
You can create aliases for SQL Server instances but not for databases.