doc-exports/docs/dws/dev/dws_06_0124.html
Lu, Huayi a24ca60074 DWS DEVELOPER 811 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2023-01-19 13:37:49 +00:00

104 lines
22 KiB
HTML

<a name="EN-US_TOPIC_0000001098830946"></a><a name="EN-US_TOPIC_0000001098830946"></a>
<h1 class="topictitle1">ALTER FOREIGN TABLE (for HDFS or OBS)</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001098830946__s57d9dea5dbcc42f99062788434d82299"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001098830946__a47d757137be04837825173873fee3169"><strong id="EN-US_TOPIC_0000001098830946__b45056406587">ALTER FOREIGN TABLE</strong> modifies an HDFS or OBS foreign table.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001098830946__s861dac7b5c7540e981f240b4e2052507"><h4 class="sectiontitle">Precautions</h4><p id="EN-US_TOPIC_0000001098830946__a77d15996bd3441748940cf27e467f3c7">None</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001098830946__s3bdb4f4f0c5e46f9a35c5474f6f70328"><h4 class="sectiontitle">Syntax</h4><ul id="EN-US_TOPIC_0000001098830946__u422e1e0147eb4c56bff87df31e45fe64"><li id="EN-US_TOPIC_0000001098830946__li6231005817">Set a foreign table's attributes.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830946__screen2698157143714"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">ALTER</span><span class="w"> </span><span class="k">FOREIGN</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">table_name</span><span class="w"></span>
<span class="w"> </span><span class="k">OPTIONS</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="err">{</span><span class="p">[</span><span class="w"> </span><span class="k">ADD</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">DROP</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">option</span><span class="w"> </span><span class="p">[</span><span class="s1">'value'</span><span class="p">]</span><span class="err">}</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]);</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
</li><li id="EN-US_TOPIC_0000001098830946__lfe824ba5ff7d4542b622906e7b55e254">Set the owner of the foreign table. <div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830946__s966b3a866d70485aba4c008f698b25d9"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">ALTER</span><span class="w"> </span><span class="k">FOREIGN</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="n">tablename</span><span class="w"> </span>
<span class="w"> </span><span class="k">OWNER</span><span class="w"> </span><span class="k">TO</span><span class="w"> </span><span class="n">new_owner</span><span class="p">;</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
</li></ul>
<ul id="EN-US_TOPIC_0000001098830946__u7fc1210afd50402386666da17bec66cf"><li id="EN-US_TOPIC_0000001098830946__li32675510236">Update a foreign table column.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830946__screen92677582318"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">ALTER</span><span class="w"> </span><span class="k">FOREIGN</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">table_name</span><span class="w"></span>
<span class="w"> </span><span class="k">MODIFY</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="n">data_type</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="k">constraint_name</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">ENABLE</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="k">constraint_name</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...]</span><span class="w"> </span><span class="p">);</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
</li><li id="EN-US_TOPIC_0000001098830946__lbf72c4436dc44e1a9121a763cbbd1933">Modify the column of the foreign table.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830946__sa78ca5c3396246ecab4037da344b190d"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">ALTER</span><span class="w"> </span><span class="k">FOREIGN</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="n">tablename</span><span class="w"> </span>
<span class="w"> </span><span class="n">action</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">];</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
<div class="p" id="EN-US_TOPIC_0000001098830946__ad4db2804f12342ecbafd9a80ebfd839e">The <strong id="EN-US_TOPIC_0000001098830946__b842352706151610">action</strong> syntax is as follows:<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830946__se1721bacc9994f758f0c887baf765aef"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span>
<span class="normal">5</span>
<span class="normal">6</span>
<span class="normal">7</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">ALTER</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">COLUMN</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="k">DATA</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">TYPE</span><span class="w"> </span><span class="n">data_type</span><span class="w"></span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">ALTER</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">COLUMN</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">DROP</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"></span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">ALTER</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">COLUMN</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="k">STATISTICS</span><span class="w"> </span><span class="p">[</span><span class="n">PERCENT</span><span class="p">]</span><span class="w"> </span><span class="nb">integer</span><span class="w"></span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">ALTER</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">COLUMN</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="k">OPTIONS</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="err">{</span><span class="p">[</span><span class="w"> </span><span class="k">ADD</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">DROP</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">option</span><span class="w"> </span><span class="p">[</span><span class="s1">'value'</span><span class="p">]</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">])</span><span class="w"></span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">MODIFY</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="n">data_type</span><span class="w"></span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">MODIFY</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="k">constraint_name</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">ENABLE</span><span class="w"> </span><span class="p">]</span><span class="w"></span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">MODIFY</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="k">constraint_name</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">NULL</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
</div>
<p id="EN-US_TOPIC_0000001098830946__a1599ea094fec4833b43a542a8191fb4f">For details, see <a href="dws_06_0142.html">ALTER TABLE</a>.</p>
</li></ul>
</div>
<ul id="EN-US_TOPIC_0000001098830946__u8a720e46d32341198eddc7703383adc2"><li id="EN-US_TOPIC_0000001098830946__l7c09c8b298f44aeb859abf7fac5fd0a5">Add a foreign table informational constraint.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830946__s9373c90dcfc44d0cbb346f697f3263d0"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">ALTER</span><span class="w"> </span><span class="k">FOREIGN</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="n">tablename</span><span class="w"></span>
<span class="w"> </span><span class="k">ADD</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="k">constraint_name</span><span class="w"> </span><span class="p">]</span><span class="w"></span>
<span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="k">PRIMARY</span><span class="w"> </span><span class="k">KEY</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">UNIQUE</span><span class="w"> </span><span class="err">}</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="p">)</span><span class="w"></span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="n">ENFORCED</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">ENABLE</span><span class="w"> </span><span class="n">QUERY</span><span class="w"> </span><span class="n">OPTIMIZATION</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">DISABLE</span><span class="w"> </span><span class="n">QUERY</span><span class="w"> </span><span class="n">OPTIMIZATION</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">ENFORCED</span><span class="w"> </span><span class="p">];</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001098830946__aa5e86761566b4d23b4cca70cf6f5c52c">For parameters about adding an informational constraint to a foreign table, see <a href="dws_06_0161.html#EN-US_TOPIC_0000001145830873__s755e54aa01f04a4bb44806bedcebdab4">Parameter Description</a> in CREATE FOREIGN TABLE (For HDFS).</p>
</li><li id="EN-US_TOPIC_0000001098830946__lf232a47367ad40b7af69aba2c5778aaf">Remove a foreign table informational constraint.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830946__s44d98c3f413346038e6082b1557280b7"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">ALTER</span><span class="w"> </span><span class="k">FOREIGN</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">IF</span><span class="w"> </span><span class="k">EXISTS</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="n">tablename</span><span class="w"> </span>
<span class="w"> </span><span class="k">DROP</span><span class="w"> </span><span class="k">CONSTRAINT</span><span class="w"> </span><span class="k">constraint_name</span><span class="w"> </span><span class="p">;</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
</li></ul>
<div class="section" id="EN-US_TOPIC_0000001098830946__s8d3b0090816744e0930e0822d5fecf52"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001098830946__u2e3e97100b674198861630b36097eea3"><li id="EN-US_TOPIC_0000001098830946__lc090ec05ae614b80bb9a948ff687df30"><strong id="EN-US_TOPIC_0000001098830946__a4f5e121e8fd44f13b17b8ca1f0baf56e">IF EXISTS</strong><p id="EN-US_TOPIC_0000001098830946__a946799bc5a344c06a13bc7eaafb69f3a">Sends a notification instead of an error if no tables have identical names. The notification prompts that the table you are querying does not exist.</p>
</li><li id="EN-US_TOPIC_0000001098830946__l4c856c90264e468d9da12896cbc1c9bd"><strong id="EN-US_TOPIC_0000001098830946__a9fe2c3d20fcc4f46ae16956951a19b57">tablename</strong><p id="EN-US_TOPIC_0000001098830946__a3c0e0a8fd76c470b8ce3adea09458b04">Specifies the name of an existing foreign table to be modified.</p>
<p id="EN-US_TOPIC_0000001098830946__a228f763fd7294819bf1b8ae4c4e6b271">Value range: an existing foreign table name</p>
</li><li id="EN-US_TOPIC_0000001098830946__la431a241fb884e978368fac8ae651cb8"><strong id="EN-US_TOPIC_0000001098830946__a2956e43b807e4d8c8678c6fc21d1eb7d">new_owner</strong><p id="EN-US_TOPIC_0000001098830946__aef96857125184eb0bc1148614f0cef26">Specifies the new owner of the foreign table.</p>
<p id="EN-US_TOPIC_0000001098830946__a382c49b508a1408191caac61acb7b374">Value range: A string indicating a valid user name.</p>
</li><li id="EN-US_TOPIC_0000001098830946__l60a667e05b4a4e338ad57c6893d0b29c"><strong id="EN-US_TOPIC_0000001098830946__a139964500cdf4867bc88b79536e5723d">data_type</strong><p id="EN-US_TOPIC_0000001098830946__abaffb1368e444d87bfa3ddffe400ed17">Specifies the new type for an existing column.</p>
<p id="EN-US_TOPIC_0000001098830946__aaa50010abd8044599f8ce6008745d607">Value range: a string. It must comply with the naming convention.</p>
</li><li id="EN-US_TOPIC_0000001098830946__l028f6921451f49c79cd0bbca438f4e63"><strong id="EN-US_TOPIC_0000001098830946__a0c77878df1b64a899f4821d555c12ea4">constraint_name</strong><p id="EN-US_TOPIC_0000001098830946__a3d3ec317d80b4b26863667110b6128e8">Specifies the name of a constraint to add or delete.</p>
</li><li id="EN-US_TOPIC_0000001098830946__l7934fd585bab45fab0ae1de3ad4f852f"><strong id="EN-US_TOPIC_0000001098830946__a71bd69b0d3924157b2b72dc56ec3cad7">column_name</strong><p id="EN-US_TOPIC_0000001098830946__a75d114e97f434d58aa4e18d9f158ed35">Specifies the name of an existing column.</p>
<p id="EN-US_TOPIC_0000001098830946__adcf3931271674d37b5526c4615db3d23">Value range: a string. It must comply with the naming convention.</p>
</li></ul>
<p id="EN-US_TOPIC_0000001098830946__a382eb5a22139409093f2df1c223000d0">For details on how to modify other parameters in the foreign table, such as <strong id="EN-US_TOPIC_0000001098830946__b55021224152911">IF EXISTS</strong>, see <a href="dws_06_0142.html#EN-US_TOPIC_0000001145910731__s3e87132692794964b56e3ba420e7b544">Parameter Description</a> in <strong id="EN-US_TOPIC_0000001098830946__b4508192416296">ALTER TABLE</strong>.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001098830946__s8302a739997543e0a22f9ee43ce9bfbf"><a name="EN-US_TOPIC_0000001098830946__s8302a739997543e0a22f9ee43ce9bfbf"></a><a name="s8302a739997543e0a22f9ee43ce9bfbf"></a><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001098830946__p8201113016286">Change the type of the <strong id="EN-US_TOPIC_0000001098830946__b619212281406">r_name</strong> column to <strong id="EN-US_TOPIC_0000001098830946__b1843625774020">text</strong> in the <strong id="EN-US_TOPIC_0000001098830946__b169012106413">ft_region</strong> foreign table.</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830946__screen153383711284"><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">ALTER</span><span class="w"> </span><span class="k">FOREIGN</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">ft_region</span><span class="w"> </span><span class="k">ALTER</span><span class="w"> </span><span class="n">r_name</span><span class="w"> </span><span class="k">TYPE</span><span class="w"> </span><span class="nb">TEXT</span><span class="p">;</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
<div class="p" id="EN-US_TOPIC_0000001098830946__p10983174219405">Run the following command to mark the <strong id="EN-US_TOPIC_0000001098830946__b5649422184213">r_name</strong> column of the <strong id="EN-US_TOPIC_0000001098830946__b1847293004216">ft_region</strong> foreign table as <strong id="EN-US_TOPIC_0000001098830946__b4709734174219">not null</strong>:<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830946__sa9ac0c08bc1f43158b422d0124578c2d"><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">ALTER</span><span class="w"> </span><span class="k">FOREIGN</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">ft_region</span><span class="w"> </span><span class="k">ALTER</span><span class="w"> </span><span class="n">r_name</span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">;</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001098830946__s1d9765c9720a460b8998648bc43a7744"><h4 class="sectiontitle">Links</h4><p id="EN-US_TOPIC_0000001098830946__a7c561b868acc4347abaf995a4278a1a0"><a href="dws_06_0161.html">CREATE FOREIGN TABLE (SQL on OBS or Hadoop)</a>, <a href="dws_06_0192.html">DROP FOREIGN TABLE</a></p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0118.html">DDL Syntax</a></div>
</div>
</div>