SQL Server: avoiding hard coding of database name in cross-database views
- by codeulike
So, lets say you have two SQL Server Databases on the same server that reference each others tables in their Views, Functions and Stored Procedures.
You know, things like this:
use database_foo
create view spaghetti
as
select f.col1, c.col2
from fusilli f
inner join database_bar.dbo.conchigli c on f.id = c.id
(I know that cross-database views are not very good practice, but lets just say you're stuck with it)
Are there any good techniques to avoid 'hard coding' the database names?
(So that should you need to occasionally re-point to a different database - for testing perhaps - you don't need to edit loads of views, fns, sps)
I'm interested in SQL 2005 or SQL 2008 solutions. Cheers.