创建视图索引首先要把视图绑定到架构

alter view view_prod_ProductProgress WITH SCHEMABINDING 
as
SELECT * from dbo.T1  as a inner join dbo.T2 as b on a.id=b.id

绑定到架构时,使用表要由两部分构成,就是 dbo.T1

 

接下来创建索引

if (exists (select * from sys.indexes where name = 'idx_prod_ProductProgress_Sht'))
    drop index view_prod_ProductProgress.idx_prod_ProductProgress_Sht
go
create index idx_prod_ProductProgress_Sht
on
view_prod_ProductProgress(ProductProgressSht);

 

报错:无法对视图 'view_prod_ProductProgress' 创建 索引。它没有唯一聚集索引。

所以首先要创建聚集索引

if (exists (select * from sys.indexes where name = 'idx_prod_ProductProgress_Sht'))
    drop index view_prod_ProductProgress.idx_prod_ProductProgress_Sht
go
create UNIQUE CLUSTERED index idx_prod_ProductProgress_Sht
on
view_prod_ProductProgress(ProductProgressSht);

 

 

相关文章:

  • 2022-12-23
  • 2021-10-01
  • 2022-01-02
  • 2022-12-23
  • 2022-01-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-27
  • 2021-10-13
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-06-18
  • 2021-05-22
相关资源
相似解决方案