怎么写这么一个视图索引(View Index)?
我有2个table(table1, table2),要把他们联合起来更具求一个和。并且必须把id作为view的索引index(因为我在其他地方还要用到这个view和其他table INNER JOIN)
他就会有出错信息
Msg 10109, Level 16, State 1, Line 2
Cannot create index on view "dbo.vw_Final" because it references derived table "T1" (defined by SELECT statement in FROM clause). Consider removing the reference to the derived table or not indexing the view.
我理解就是用UNION产生的table不能index。那我应该怎么办呢?
CREATE View dbo.vw_Final WITH SCHEMABINDING
AS
SELECT id , SUM(Quantity) AS Quantity
FROM ( SELECT id, Quantity FROM Table1
UNION ALL
SELECT id, Quantity FROM Table2) AS T1
GROUP BY id
GO
CREATE UNIQUE CLUSTERED INDEX IDX_vw_Final_id
ON vw_Final(id);
GO
他就会有出错信息
Msg 10109, Level 16, State 1, Line 2
Cannot create index on view "dbo.vw_Final" because it references derived table "T1" (defined by SELECT statement in FROM clause). Consider removing the reference to the derived table or not indexing the view.
我理解就是用UNION产生的table不能index。那我应该怎么办呢?
...全文
相关推荐
视图上使用索引的一个注意点
视图上使用索引的一个注意点,讲解了一个常犯的建了索引而没起作用的错误
视图和索引的创建和使用实验报告.pdf
视图和索引的创建和使用实验报告.pdf
PostgreSQL物化视图(materialized view)过程解析
主要介绍了PostgreSQL物化视图(materialized view)过程解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
SQL视图与索引总结
区分视图与索引(1) 创建视图:(以SQL语句) create view v_GoodsInfo_ClassName_UnitName [with encryption--对CREATE VIEW语句文本的项进行加密] as select GoodsID 商品编号,ClassName 类别名,Price 价格,StoreNum 库存数量,UnitName 单位,Price*StoreNum 销售金额 from GoodsInfo G1,GoodsClass G2,GoodsUnit G3 where G1.ClassID=G2.ClassID and G1.GoodsUnit=G3.UnitID and ClassID='SPLB03'
oracle数据库 视图和索引
实验六 视图和索引 实验目的 (1)了解视图的重要性 (2)掌握视图的建立 (3)掌握视图的使用 (4)掌握索引的使用方法 (5)掌握索引的概念及分类


应用实例
