forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com> Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
29 lines
4.8 KiB
HTML
29 lines
4.8 KiB
HTML
<a name="dli_08_0130"></a><a name="dli_08_0130"></a>
|
|
|
|
<h1 class="topictitle1">Creating a View</h1>
|
|
<div id="body8662426"><div class="section" id="dli_08_0130__en-us_topic_0114776224_en-us_topic_0093946773_sda6e53e247f04a66ad84515c42ed5a6c"><h4 class="sectiontitle">Function</h4><p id="dli_08_0130__en-us_topic_0114776224_en-us_topic_0093946773_a343d9a6cdd974f33a88173f14b74a52d">This statement is used to create views.</p>
|
|
</div>
|
|
<div class="section" id="dli_08_0130__en-us_topic_0114776224_en-us_topic_0093946773_s995533fd18194fe08f398f18f065cdf3"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="dli_08_0130__en-us_topic_0114776224_screen122719365584"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="p">[</span><span class="k">OR</span><span class="w"> </span><span class="k">REPLACE</span><span class="p">]</span><span class="w"> </span><span class="k">VIEW</span><span class="w"> </span><span class="n">view_name</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="n">select_statement</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_08_0130__en-us_topic_0114776224_en-us_topic_0093946773_se62db8684fc443979516b91a6b018a5c"><h4 class="sectiontitle">Keywords</h4><ul id="dli_08_0130__en-us_topic_0114776224_en-us_topic_0093946773_u2a2e725d6133427f951344664b111e7c"><li id="dli_08_0130__en-us_topic_0114776224_en-us_topic_0093946773_l89104ba744fa47ffba694fc735438ab2">CREATE VIEW: creates views based on the given select statement. The result of the select statement will not be written into the disk.</li><li id="dli_08_0130__en-us_topic_0114776224_li19351029703">OR REPLACE: updates views using the select statement. No error is reported and the view definition is updated using the SELECT statement if a view exists.</li></ul>
|
|
</div>
|
|
<div class="section" id="dli_08_0130__en-us_topic_0114776224_en-us_topic_0093946773_s519e38143dbb44a6bff30c2a3297a58a"><h4 class="sectiontitle">Precautions</h4><ul id="dli_08_0130__en-us_topic_0114776224_ul89342096539"><li id="dli_08_0130__en-us_topic_0114776224_li09341394533">The view to be created must not exist in the current database. Otherwise, an error will be reported. When the view exists, you can add keyword <strong id="dli_08_0130__b429211072413">OR REPLACE</strong> to avoid the error message.</li><li id="dli_08_0130__en-us_topic_0114776224_li1252841517534">The table or view information contained in the view cannot be modified. If the table or view information is modified, the query may fail.</li><li id="dli_08_0130__li17421025181715">If the compute engines used for creating tables and views are different, the view query may fail due to incompatible varchar types.<p id="dli_08_0130__p128439404192"><a name="dli_08_0130__li17421025181715"></a><a name="li17421025181715"></a>For example, if a table is created using Spark 3.<em id="dli_08_0130__i1564885319351">x</em>, you are advised to use Spark 2.<em id="dli_08_0130__i217816591358">x</em> to create a view.</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="dli_08_0130__en-us_topic_0114776224_en-us_topic_0093946773_s9f2f3142c926488a947e1a5d9628defc"><h4 class="sectiontitle">Example</h4><p id="dli_08_0130__en-us_topic_0114776224_en-us_topic_0093946773_aea0a7b5112b64333b1b924c5eb4eea81">To create a view named <strong id="dli_08_0130__en-us_topic_0093946773_en-us_topic_0047959946_en-us_topic_0039551609_b32304223105838">student_view</strong> for the queried ID and name of the <strong id="dli_08_0130__en-us_topic_0093946773_en-us_topic_0047959946_en-us_topic_0039551609_b22302554105838">student</strong> table, run the following statement:</p>
|
|
<div class="codecoloring" codetype="Sql" id="dli_08_0130__en-us_topic_0114776224_screen722834115917"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">VIEW</span><span class="w"> </span><span class="n">student_view</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="n">id</span><span class="p">,</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">student</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0129.html">Views</a></div>
|
|
</div>
|
|
</div>
|
|
|