什么时候立即物化视图更新

时间:2012-05-03 09:36:12

标签: sql materialized-views sqlanywhere

我使用SQL Anywhere 11。

我有以下观点:

CREATE MATERIALIZED VIEW "DBA"."PointsAcc"( /* view_column_name, ... */ )
IN "SYSTEM" AS
select sum(PL.Points) AS Sum, DP.UserUID, COUNT(*) AS cnt
FROM Points DP
KEY JOIN PointLine PL
KEY JOIN PointHead PH
GROUP BY DP.UserUID

我在PointLine中有一个触发器,应该从该视图中选择总和:

CREATE TRIGGER "WorkOnPoints" AFTER INSERT, DELETE
ORDER 1 ON "DBA"."Points"
REFERENCING OLD AS oldrow NEW AS newrow 
FOR EACH ROW
BEGIN
    declare @points integer;
    set @points = (isnull((select isnull(Sum, 0)) FROM PointsAcc where UserUID = newrow.UserUID), 0)) 
END;

@points变量现在包含插入或删除行之前的总和。如何从触发器中的视图中获取更新的总和?

1 个答案:

答案 0 :(得分:1)

这取决于您当前使用的SQLA版本。

如果您没有创建具有立即刷新的视图选项,则必须调用

REFRESH MATERIALIZED VIEW view-list

有关详细信息,请查看这些链接

http://dcx.sybase.com/index.html#1201/en/dbreference/alter-materialized-view-statement.html

并且

http://dcx.sybase.com/1201/en/dbreference/refresh-materialized-view-statement.html