RDBMS の view はいつ使われるか

StackOverflow より引用及び翻訳(意訳 加筆)

より正確な内容は本記事下段のリンク先参照

f:id:mat5ukawa:20160302230736j:plain

view はいくつか良いものを提供してくれる

1. View は複雑さを隠すことができる

何個かテーブルを結合したり、複雑な計算したり、
複雑ロジックを組んだクエリが必要な場合
こいつらは view に組込むことができる
また、view からはテーブルと同じように
select で属性を取得することができる

2. View はセキュリティメカニズムに使われうる

view は特定の行 必要ならば列を制約し 項目をテーブルから取得できる
その view にはパーミッションをつけることも可能だ
つまりこれは、ユーザーからの必要なデータだけを見える化した
「権限」を設けることだ

3. View はレガシーコードの簡潔化に使われうる

たくさんの「ぶっ飛んだテーブル」をリファクタしたい時
これらテーブルと同じ名を持った view へ置き換えが可能だ
view のスキーマは(ユーザーから見れば) 置き換わるテーブルスキーマと同じままで
リファクタされる実際のテーブルスキーマは変わることになる
( つまり「ユーザーから見れば何も変わってない」
 「リファクタする側からすれば色々手を加えられる」)
これで、「ぶっ飛んだテーブル」は自分の思いのままにリファクタができる

以上が view の有用な使い方の「数あるうち」だ
A view provides several benefits.

1. Views can hide complexity

If you have a query that requires joining several tables,
or has complex logic or calculations,
you can code all that logic into a view,
then select from the view just like you would a table.

2. Views can be used as a security mechanism

A view can select certain columns and/or rows from a table,
and permissions set on the view instead of the underlying tables.
This allows surfacing only the data that a user needs to see.

3. Views can simplify supporting legacy code

If you need to refactor a table that would break a lot of code,
you can replace the table with a view of the same name.
The view provides the exact same schema as the original table,
while the actual schema has changed.
This keeps the legacy code that references the table from breaking,
allowing you to change the legacy code at your leisure.

These are just some of the many examples of how views can be useful.

stackoverflow.com