Our business system consists of 4 separate database. One of these is a
Reference database that stores common look up tables, such as Countries,
Provinces, States, etc. When we want to access this information from
another database, we always prefix the table with the db name, then the
owner, as in:
select * from Reference.dbo.Country
Since there is no Country table in any of the other databases, I was
wondering if there was a way to 'instruct' SQL to always look in the
Reference database for a table called 'Country'. This would make coding
the stored procedures (and working in Query Analyzer) a bit less verbose,
but I do NOT want to sacrifice performance. Plus, I don't even know if this
possible. One of the developers here mentioned that Oracle has global
prefixes, or constants or something like that, that allows you to define
this. So far, the only thing I've come up with is to create a view in each
of the other databases with the same name as the tables in Reference, where
the view is something like:
Create View Country As Select * from Reference.dbo.Country
Any thoughts?On Sun, 3 Apr 2005 21:19:55 -0600, Dave Slinn wrote:
(snip)
> select * from Reference.dbo.Country
>Since there is no Country table in any of the other databases, I was
>wondering if there was a way to 'instruct' SQL to always look in the
>Reference database for a table called 'Country'.
Hi Dave,
No, there is no such option in SQL Server.
Sidenote - even if there was, I'd probably recommend against using it,
since it would slow things down. Consider the well documented
performance difference between "SELECT somecol FROM sometable" and
"SELECT somecol FROM dbo.sometable". The first will check first for a
table called sometable owned by the current user before going to the
sometable table owned by dbo; the second will skip the first step.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment