Viewでもサマリーテーブルでも同じ答えを得ることは出来るが、それぞれメリット/デメリットがある。
サマリーテーブルは一度作成すれば計算が不要なので、Viewと比較すると処理が早い。
反対にViewの処理は毎回計算されるので遅いが常に最新のデータを返してくれる。
用途によって上手に使い分ければよい。

1) The advantage of using a summary table over using a view is that a summary table is often faster.
Result set is created only once (on table creation time).
2) The disadvantage of a summary table is that its content is static and might become stale

1) View’s result set has to be calculated each time the view is selected.
2) View always provides the most recent data.


CREATE VIEW View_Surface
(Name, ContinentSurface, CountryAvgSurface)
AS SELECT Continent, SUM(SurfaceArea),
AVG(SurfaceArea)
FROM Country GROUP BY Continent;


CREATE TABLE Table_Surface
AS SELECT Continent AS Name,
SUM(SurfaceArea) AS ContinentSurface,
AVG(SurfaceArea) AS CountryAvgSurface
FROM Country GROUP BY Continent;

view_vs_table

Comments are closed.

Post Navigation