create_view.sgml
上传用户:blenddy
上传日期:2007-01-07
资源大小:6495k
文件大小:6k
源码类别:

数据库系统

开发平台:

Unix_Linux

  1. <refentry id="SQL-CREATEVIEW">
  2.  <refmeta>
  3.   <refentrytitle>
  4.    CREATE VIEW
  5.   </refentrytitle>
  6.   <refmiscinfo>SQL - Language Statements</refmiscinfo>
  7.  </refmeta>
  8.  <refnamediv>
  9.   <refname>
  10.    CREATE VIEW
  11.   </refname>
  12.   <refpurpose>
  13.    Constructs a virtual table
  14.   </refpurpose>
  15.  </refnamediv>
  16.  <refsynopsisdiv>
  17.   <refsynopsisdivinfo>
  18.    <date>1998-09-21</date>
  19.   </refsynopsisdivinfo>
  20.   <synopsis>
  21. CREATE VIEW <replaceable class="PARAMETER">view</replaceable>
  22.     AS SELECT <replaceable class="PARAMETER">query</replaceable>
  23.   </synopsis>
  24.   <refsect2 id="R2-SQL-CREATEVIEW-1">
  25.    <refsect2info>
  26.     <date>1998-09-21</date>
  27.    </refsect2info>
  28.    <title>
  29.     Inputs
  30.    </title>
  31.    <para>
  32.     <variablelist>
  33.      <varlistentry>
  34.       <term><replaceable class="parameter">view</replaceable></term>
  35.       <listitem>
  36.        <para>
  37. The name of a view to be created.
  38.        </para>
  39.       </listitem>
  40.      </varlistentry>
  41.      <varlistentry>
  42.       <term><replaceable class="parameter">query</replaceable></term>
  43.       <listitem>
  44.        <para>
  45. An SQL query which will provide the columns and rows of the view.
  46.        </para>
  47.        <para>
  48. Refer to the SELECT statement for more information
  49. about valid arguments.
  50.        </para>
  51.       </listitem>
  52.      </varlistentry>
  53.     </variablelist>
  54.    </para>
  55.   </refsect2>
  56.   <refsect2 id="R2-SQL-CREATEVIEW-2">
  57.    <refsect2info>
  58.     <date>1998-09-21</date>
  59.    </refsect2info>
  60.    <title>
  61.     Outputs
  62.    </title>
  63.    <para>
  64.     <variablelist>
  65.      <varlistentry>
  66.       <term><computeroutput>
  67. CREATE
  68.        </computeroutput></term>
  69.       <listitem>
  70.        <para>
  71. The message returned if the view is successfully created.
  72.        </para>
  73.       </listitem>
  74.      </varlistentry>
  75.      <varlistentry>
  76.       <term><computeroutput>
  77. ERROR:  Relation '<replaceable class="parameter">view</replaceable>' already exists
  78.        </computeroutput></term>
  79.       <listitem>
  80.        <para>
  81. This error occurs if the view specified already exists in the database.
  82.        </para>
  83.       </listitem>
  84.      </varlistentry>
  85.      <varlistentry>
  86.       <term><computeroutput>
  87. NOTICE create: attribute named "<replaceable class="parameter">column</replaceable>" has an unknown type
  88.        </computeroutput></term>
  89.       <listitem>
  90.        <para>
  91. The view will be created having a column with an unknown type
  92. if you do not specify it. For example, the following command gives
  93. an error:
  94. <programlisting>
  95. CREATE VIEW vista AS SELECT 'Hello World'
  96. </programlisting>
  97. whereas this command does not:
  98. <programlisting>
  99. CREATE VIEW vista AS SELECT 'Hello World'::text
  100. </programlisting>
  101.        </para>
  102.       </listitem>
  103.      </varlistentry>
  104.     </variablelist>
  105.    </para>
  106.   </refsect2>
  107.  </refsynopsisdiv>
  108.  <refsect1 id="R1-SQL-CREATEVIEW-1">
  109.   <refsect1info>
  110.    <date>1998-09-21</date>
  111.   </refsect1info>
  112.   <title>
  113.    Description
  114.   </title>
  115.   <para>
  116.    <command>CREATE VIEW</command> will define a view of a table. This view is
  117.    not physically materialized. Specifically, a query
  118.    rewrite retrieve rule is automatically generated
  119.    to support retrieve operations on views.
  120.   </para>
  121.   <refsect2 id="R2-SQL-CREATEVIEW-3">
  122.    <refsect2info>
  123.     <date>1998-09-21</date>
  124.    </refsect2info>
  125.    <title>
  126.     Notes
  127.    </title>
  128.    <para>
  129.     Use the <command>DROP VIEW</command> statement to drop views.
  130.    </para>
  131.   </refsect2>
  132.   <refsect2 id="R2-SQL-CREATEVIEW-4">
  133.    <refsect2info>
  134.     <date>1998-09-21</date>
  135.    </refsect2info>
  136.    <title>
  137.     Bugs
  138.    </title>
  139.    <para>
  140.     Currently, views are read only.
  141.    </para>
  142.   </refsect2>
  143.  </refsect1>
  144.  <refsect1 id="R1-SQL-CREATEVIEW-2">
  145.   <title>
  146.    Usage
  147.   </title>
  148.   <para>
  149.    Create a view consisting of all Comedy films:
  150.    <programlisting>
  151. CREATE VIEW kinds AS
  152.     SELECT *
  153.     FROM films
  154.     WHERE kind = 'Comedy';
  155. SELECT * FROM kinds;
  156. code |title                    |did| date_prod|kind      |len
  157. -----+-------------------------+---+----------+----------+------
  158. UA502|Bananas                  |105|1971-07-13|Comedy    | 01:22
  159. C_701|There's a Girl in my Soup|107|1970-06-11|Comedy    | 01:36
  160.    </programlisting>
  161.   </para>
  162.  </refsect1>
  163.  
  164.  <refsect1 id="R1-SQL-CREATEVIEW-3">
  165.   <title>
  166.    Compatibility
  167.   </title>
  168.   <para>
  169.   </para>
  170.   
  171.   <refsect2 id="R2-SQL-CREATEVIEW-5">
  172.    <refsect2info>
  173.     <date>1998-09-21</date>
  174.    </refsect2info>
  175.    <title>
  176.     SQL92
  177.    </title>
  178.    <para>
  179.     SQL92 specifies some additional capabilities for the
  180.     <command>CREATE VIEW</command> statement:
  181.    </para>
  182.    <synopsis>
  183. CREATE VIEW <replaceable class="parameter">view</replaceable> [ <replaceable class="parameter">column</replaceable> [, ...] ]
  184.     AS SELECT <replaceable class="parameter">expression</replaceable> [ AS <replaceable class="parameter">colname</replaceable> ] [, ...]
  185.     FROM <replaceable class="parameter">table</replaceable> [ WHERE <replaceable class="parameter">condition</replaceable> ]
  186.     [ WITH [ CASCADE | LOCAL ] CHECK OPTION ]
  187.    </synopsis>
  188.    <para>
  189.     The optional clauses for the full SQL92 command are:
  190.    <variablelist>
  191.      <varlistentry>
  192.       <term>CHECK OPTION</term>
  193.       <listitem>
  194.        <para>
  195. This option is to do with updatable views.
  196. All INSERTs and UPDATEs on the view will be
  197. checked to ensure data satisfy the view-defining
  198. condition. If they do not, the update will be rejected.
  199.        </para>
  200.       </listitem>
  201.      </varlistentry>
  202.      <varlistentry>
  203.       <term>LOCAL</term>
  204.       <listitem>
  205.        <para>
  206. Check for integrity on this view.
  207.        </para>
  208.       </listitem>
  209.      </varlistentry>
  210.      <varlistentry>
  211.       <term>CASCADE</term>
  212.       <listitem>
  213.        <para>
  214. Check for integrity on this view and on any dependent
  215. view. CASCADE is assumed if neither CASCADE nor LOCAL is specified.
  216.        </para>
  217.       </listitem>
  218.      </varlistentry>
  219.     </variablelist>
  220.    </para>
  221.   </refsect2>
  222.  </refsect1>
  223. </refentry>
  224. <!-- Keep this comment at the end of the file
  225. Local variables:
  226. mode: sgml
  227. sgml-omittag:nil
  228. sgml-shorttag:t
  229. sgml-minimize-attributes:nil
  230. sgml-always-quote-attributes:t
  231. sgml-indent-step:1
  232. sgml-indent-data:t
  233. sgml-parent-document:nil
  234. sgml-default-dtd-file:"../reference.ced"
  235. sgml-exposed-tags:nil
  236. sgml-local-catalogs:"/usr/lib/sgml/catalog"
  237. sgml-local-ecat-files:nil
  238. End:
  239. -->