--创建索引视图
create view 视图名 with schemabinding 
as
select 语句
go
 
---创建索引视图需要注意的几点
1. 创建索引视图的时候需要指定表所属的架构
--错误写法
create view v_f with schemabinding 
as
select
   a.a,a.b,b.a,b.b
from
   join 
on
   a.id=b.id
go
 
---正确写法:
create view v_f with schemabinding 
as
select
   a.a,a.b,b.a,b.b
from
   dbo.a join dbo.b 
on
   a.id=b.id
go
 
 
2.在创建索引视图的select语句时,不使用*,必须指定具体的列名
--错误写法
create view v_f with schemabinding 
as
select
   *
from
   dbo.a join dbo.b 
on
   a.id=b.id
go
 
---正确写法
create view v_f with schemabinding 
as
select
   a.a,a.b,b.a,b.b
from
   dbo.a join dbo.b 
on
   a.id=b.id
go
 
3.在创建索引视图的select 语句中,不能存在重复的列名,这个不举例了
 
4. 只能为索引视图创建唯一聚集索引
--正确的写法
create unique clustered index ix_uniquetb on v_tb
go
 
--错误的写法 
create clustered index ix_uniquetb on v_tb
go
 
 

相关文章:

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