开发者

SQL Server: avoiding hard coding of database name in cross-database views

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 o开发者_如何学Pythonccasionally 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.


You can try using Synonyms. That way you can change what the synonym points to without having the change your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜