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

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?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Brian CroweDatabase AdministratorCommented:
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.
Scott PletcherSenior DBACommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
You can create aliases for SQL Server instances but not for databases.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.