Yang, Tong 48706b7552 MRS COMP-LTS 320-lts.1 version
Reviewed-by: Kacur, Michal <michal.kacur@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2024-04-12 12:51:10 +00:00

67 lines
6.7 KiB
HTML

<a name="mrs_01_24499"></a><a name="mrs_01_24499"></a>
<h1 class="topictitle1">Altering a Column</h1>
<div id="body0000001585034889"><div class="section" id="mrs_01_24499__en-us_topic_0265792790_sa1cb229bf26b4a7a8efd1716defb63de"><h4 class="sectiontitle">Function</h4><p id="mrs_01_24499__en-us_topic_0265792790_ac917e6d6e78044e99179c0e0f5284232">The <strong id="mrs_01_24499__b1652113223131">ALTER TABLE ... ALTER COLUMN</strong> command is used to change the attributes of a column, such as the column type, position, and comment.</p>
</div>
<div class="section" id="mrs_01_24499__en-us_topic_0265792790_sc019b10a59e9426498a678c024d74f03"><h4 class="sectiontitle">Syntax</h4><p id="mrs_01_24499__p115411424114818"><strong id="mrs_01_24499__b5541132404813">ALTER TABLE </strong><em id="mrs_01_24499__i8752171611276">Table name</em> <strong id="mrs_01_24499__b14541142454811">ALTER</strong></p>
<p id="mrs_01_24499__p2071145618449"><strong id="mrs_01_24499__b8767101664815">[COLUMN] </strong><em id="mrs_01_24499__i76601519192719">col_old_name</em> <strong id="mrs_01_24499__b420420555315">TYPE</strong><em id="mrs_01_24499__i72041055163116"> column_type</em></p>
<p id="mrs_01_24499__p9766727204812"><strong id="mrs_01_24499__b1586155814910">[COMMENT] </strong><em id="mrs_01_24499__i777772272716">col_comment</em></p>
<p id="mrs_01_24499__p165085319489"><strong id="mrs_01_24499__b71811522504">[FIRST|AFTER] </strong><em id="mrs_01_24499__i1813417262274">column_name</em></p>
</div>
<div class="section" id="mrs_01_24499__en-us_topic_0265792790_s253f086de08745ac890027c0b103cd7a"><h4 class="sectiontitle">Parameter Description</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_24499__en-us_topic_0265792790_ta69e9ecdc1554375a8a1e844b14e00c5" frame="border" border="1" rules="all"><caption><b>Table 1 </b>ALTER COLUMN parameters</caption><thead align="left"><tr id="mrs_01_24499__en-us_topic_0265792790_r61ddb6139b8d4f4ca4a88c6389f8f327"><th align="left" class="cellrowborder" valign="top" width="30%" id="mcps1.3.3.2.2.3.1.1"><p id="mrs_01_24499__en-us_topic_0265792790_aeb0bfa560fb74f1f9e584cc1ef05bb9b">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="70%" id="mcps1.3.3.2.2.3.1.2"><p id="mrs_01_24499__en-us_topic_0265792790_ae81789e97e6d4953a8342f22d64feea9">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_24499__en-us_topic_0265792790_r4a578c7015ba461bab46a5c40c46256a"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24499__en-us_topic_0265792790_ac25da7f69c964d93947693ed5b4006cb">tableName</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24499__en-us_topic_0265792790_a09288a5af7f44e36922b37de34446d94">Table name.</p>
</td>
</tr>
<tr id="mrs_01_24499__row11891114814"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24499__p2181318482">col_old_name</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24499__p18189110483">Name of the column to be altered.</p>
</td>
</tr>
<tr id="mrs_01_24499__row7604329174817"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24499__p116053297485">column_type</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24499__p186051829144818">Type of the target column.</p>
</td>
</tr>
<tr id="mrs_01_24499__row1051610168493"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24499__p0516181634919">col_comment</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24499__p175171216144918">Column comment.</p>
</td>
</tr>
<tr id="mrs_01_24499__row526813764915"><td class="cellrowborder" valign="top" width="30%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_24499__p926817376491">column_name</p>
</td>
<td class="cellrowborder" valign="top" width="70%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_24499__p1326853704916">New position to place the target column. For example, <strong id="mrs_01_24499__b44031125111718">AFTER column_name</strong> indicates that the target column is placed after <strong id="mrs_01_24499__b168261244191719">column_name</strong>.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="mrs_01_24499__en-us_topic_0265792790_s55536c9c534643ed8272f9f4b47fb407"><h4 class="sectiontitle">Example</h4><ul id="mrs_01_24499__ul63722051112818"><li id="mrs_01_24499__li43721651142818">Changing the column type<pre class="screen" id="mrs_01_24499__screen1963611232294">ALTER TABLE table1 ALTER COLUMN a.b.c TYPE bigint</pre>
<p id="mrs_01_24499__p6526204742817"><strong id="mrs_01_24499__b19656145916249">a.b.c</strong> indicates the full path of a nested column. For details about the nested column rules, see <a href="mrs_01_24498.html">Adding a Column</a>.</p>
<p id="mrs_01_24499__p1552644762810">The following changes on column types are supported:</p>
<ul id="mrs_01_24499__ul1110004412314"><li id="mrs_01_24499__li161249414314">int =&gt; long/float/double/string/decimal</li><li id="mrs_01_24499__li20126184193119">long =&gt; float/double/string/decimal</li><li id="mrs_01_24499__li3127134163119">float =&gt; double/String/decimal</li><li id="mrs_01_24499__li1127941193114">From double to string or decimal</li><li id="mrs_01_24499__li1613084143119">From decimal to decimal or string</li><li id="mrs_01_24499__li1995628125019">From string to date or decimal</li><li id="mrs_01_24499__li8131941183118">From date to string</li></ul>
</li><li id="mrs_01_24499__li18227043306">Altering other attributes<pre class="screen" id="mrs_01_24499__screen122214179304">ALTER TABLE table1 ALTER COLUMN a.b.c DROP NOT NULL
ALTER TABLE table1 ALTER COLUMN a.b.c COMMENT 'new comment'
ALTER TABLE table1 ALTER COLUMN a.b.c FIRST
ALTER TABLE table1 ALTER COLUMN a.b.c AFTER x</pre>
<p id="mrs_01_24499__p952514717288"><strong id="mrs_01_24499__b175358301350">a.b.c</strong> indicates the full path of a nested column. For details about the nested column rules, see <a href="mrs_01_24498.html">Adding a Column</a>.</p>
</li></ul>
</div>
<div class="section" id="mrs_01_24499__en-us_topic_0265792790_sbd5eea8637c94038bf6a129ab9ca129f"><h4 class="sectiontitle">Response</h4><p id="mrs_01_24499__en-us_topic_0265792790_ab3f2ebd199c342fb9103cbe4f02c7148">You can run the <strong id="mrs_01_24499__b1689810301694">DESCRIBE</strong> command to view the modified column.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_24495.html">SparkSQL Schema Evolution and Syntax Description</a></div>
</div>
</div>