バージョンごとのドキュメント一覧

3.2. ビュー #

<title>Views</title>

Refer back to the queries in <xref linkend="tutorial-join"/>. Suppose the combined listing of weather records and city location is of particular interest to your application, but you do not want to type the query each time you need it. You can create a <firstterm>view</firstterm> over the query, which gives a name to the query that you can refer to like an ordinary table: 2.6の問い合わせをもう一度参照してください。 天候の記録と都市の所在場所を結合したリストを得ることが今作っているアプリケーションにとって特に重要なのですが、この結合リストを必要とする度に問い合わせを打ち込みたくはないとしましょう。 この問い合わせに対してビューを作成し、通常のテーブルのように参照できる問い合わせに名前を付けることができます。

CREATE VIEW myview AS
    SELECT name, temp_lo, temp_hi, prcp, date, location
        FROM weather, cities
        WHERE city = name;

SELECT * FROM myview;

Making liberal use of views is a key aspect of good SQL database design. Views allow you to encapsulate the details of the structure of your tables, which might change as your application evolves, behind consistent interfaces. ビューを自由に利用することは、SQLデータベースの良い設計における重要な項目です。 ビューはテーブル構造の詳細をカプセル化しますので、アプリケーションが発展するに従いテーブル構造が変わったとしても、一貫したインタフェースを保てます。

Views can be used in almost any place a real table can be used. Building views upon other views is not uncommon. ビューは実テーブルが使用できるほとんどの場所で使えます。 他のビューに対するビューの作成も珍しくはありません。