如何在其他服务器的视图上创建架构绑定和索引?

时间:2018-10-08 06:19:05

标签: sql-server optimization indexing view schema

我尝试借助架构绑定和索引创建视图,该视图是从其他服务器表引用的。但是sql为以下查询抛出了一些错误。

 create VIEW [dbo].[Vxyz]
  with schemabinding
  AS 
  SELECT 
  ELID,USECOUNT,LASTUPDATE,TYPE,CODENE,CASNUE,NAME_ENG,ISGROUP,CHGROUP,DLink 
  IDE,LOCKBY,PhyApB,BUILDNO,PMNNumE,EINECE 
  FROM IADL.dbo.tblxyz 
  GO
  create unique clustered index IDX_xyz on [dbo]. 
  [Vxyz](ELID)

enter image description here enter image description here

发现以下错误

  

消息4512,级别16,状态3,过程IADL.dbo.tblxyz,行3 [批处理开始行11]   无法架构绑定视图'[dbo]。[Vxyz]',因为名称'IADL.dbo.tblxyz'对于架构绑定无效。名称必须为两部分格式   对象无法引用自己。   消息1939,第16级,状态1,第17行   无法在视图'[dbo]。[Vxyz]'上创建索引,因为该视图未绑定架构。

 select distinct 
    ISNULL(A.elid, B.elid) ElementID, 
    CASE when A.elid is null and B.elid is not null then 'Missing ElementID :'+ 
        B.elid+' in Mainproductsall table' when A.elid is not null 
        and B.elid is null then 'Missing ElementID :'+ A.elid+' in Genproductsall table' Else 'OK' 
    end Datastatus 
into ABC 
from [dbo].[Vxyz] As A 
full outer join [dbo].[Vxyzwa] as B on A.elid = B.elid 
where A.elid is null or B.elid is null

以上查询中的每个都是视图。根据我上面的第一个查询是从其他服务器引用的。所以我想优化,我试图创建索引。

1 个答案:

答案 0 :(得分:1)

如果您查看官方documentation,则会看到以下内容

所有引用的对象必须位于同一数据库中。

因此您不能从其他数据库引用基表。

这意味着,对于所有引用的当前数据库对象,应使用其架构名称和对象名称进行引用。