File: tutorial-views.html

package info (click to toggle)
pgadmin3 1.4.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 29,796 kB
  • ctags: 10,758
  • sloc: cpp: 55,356; sh: 6,164; ansic: 1,520; makefile: 576; sql: 482; xml: 100; perl: 18
file content (42 lines) | stat: -rw-r--r-- 2,059 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>3.2.Views</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="tutorial-advanced.html" title="Chapter3.Advanced Features">
<link rel="prev" href="tutorial-advanced.html" title="Chapter3.Advanced Features">
<link rel="next" href="tutorial-fk.html" title="3.3.Foreign Keys">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="sect1" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="tutorial-views"></a>3.2.Views</h2></div></div></div>
<a name="id569690"></a><p>    Refer back to the queries in <a href="tutorial-join.html" title="2.6.Joins Between Tables">Section2.6, &#8220;Joins Between Tables&#8221;</a>.
    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
    <em class="firstterm">view</em> over the query, which gives a name to
    the query that you can refer to like an ordinary table.

</p>
<pre class="programlisting">CREATE VIEW myview AS
    SELECT city, temp_lo, temp_hi, prcp, date, location
        FROM weather, cities
        WHERE city = name;

SELECT * FROM myview;</pre>
<p>
   </p>
<p>    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 may change as your application
    evolves, behind consistent interfaces.
   </p>
<p>    Views can be used in almost any place a real table can be used.
    Building views upon other views is not uncommon.
   </p>
</div></body>
</html>