TSQL: Create a view that accesses multiple databases

后端 未结 3 2013
孤城傲影
孤城傲影 2020-12-01 07:36

I have a special case,

for example in table ta in database A, it stores all the products I buy

table ta(
id,
name,
price
)
         


        
3条回答
  •  春和景丽
    2020-12-01 08:22

    Yes, views can reference three part named objects:

    create view A.dbo.viewname as
    select ... from A.dbo.ta as ta
    join B.dbo.tb as tb on ta.id = tb.id
    where ...
    

    There will be problems down the road with cross db queries because of backup/restore consistency, referential integrity problems and possibly mirorring failover, but those problems are inherent in having the data split across dbs.

提交回复
热议问题