Yang, Tong 6182f91ba8 MRS component operation guide_normal 2.0.38.SP20 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2022-12-09 14:55:21 +00:00

57 lines
6.8 KiB
HTML

<a name="mrs_01_1433"></a><a name="mrs_01_1433"></a>
<h1 class="topictitle1">CHANGE DATA TYPE</h1>
<div id="body1595920212170"><div class="section" id="mrs_01_1433__sd8e4ffaa71fc4034a9e2882d7c664984"><h4 class="sectiontitle">Function</h4><p id="mrs_01_1433__a1b6e3ab1a6a8455ea35fb870b4639d6e">This command is used to change the data type from INT to BIGINT or decimal precision from lower to higher.</p>
</div>
<div class="section" id="mrs_01_1433__s62a70620dabc4e4eb96778f71c580e7f"><h4 class="sectiontitle">Syntax</h4><p id="mrs_01_1433__a6b356e6432854134892ad04ebe29e30a"><b><span class="cmdname" id="mrs_01_1433__cmdname11690114192020">ALTER TABLE</span></b> <i><span class="varname" id="mrs_01_1433__v32ab5b13ac364204b51c622cbc717593">[db_name.]table_name</span></i> <b><span class="cmdname" id="mrs_01_1433__cmdname38741318182012">CHANGE</span></b> <i><span class="varname" id="mrs_01_1433__vf08a99ec72b343689f413d635c634452">col_name col_name changed_column_type</span></i>;</p>
</div>
<div class="section" id="mrs_01_1433__sd00174c8f3e8417ea0037e034192d094"><h4 class="sectiontitle">Parameter Description</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="mrs_01_1433__td330633f0f1a4e839893ee60997ac66b" frame="border" border="1" rules="all"><caption><b>Table 1 </b>CHANGE DATA TYPE parameters</caption><thead align="left"><tr id="mrs_01_1433__r520a27852cb34cb7928beb87ae57c383"><th align="left" class="cellrowborder" valign="top" width="19.439999999999998%" id="mcps1.3.3.2.2.3.1.1"><p id="mrs_01_1433__a2d7b4ba625ae4e73b3de582488dc2354">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="80.56%" id="mcps1.3.3.2.2.3.1.2"><p id="mrs_01_1433__a13d327fe75f04ee5aa721ffef31b1687">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="mrs_01_1433__r29602039075d4ee29712ba3776de3028"><td class="cellrowborder" valign="top" width="19.439999999999998%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1433__aa52e22f2600e4f7cb864be20ae67a97f">db_name</p>
</td>
<td class="cellrowborder" valign="top" width="80.56%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1433__a75965636f150489ab9dbf4e657309412">Name of the database. If this parameter is left unspecified, the current database is selected.</p>
</td>
</tr>
<tr id="mrs_01_1433__re6d39247ca1244249d7687ea10dcd0c8"><td class="cellrowborder" valign="top" width="19.439999999999998%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1433__a94889b6d62534a839457c1f3f6ecc741">table_name</p>
</td>
<td class="cellrowborder" valign="top" width="80.56%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1433__a9cc3bd83b1044286b7a79068ee33df1e">Name of the table.</p>
</td>
</tr>
<tr id="mrs_01_1433__rb4f07e1091404b65bddffe9e7e8ef91a"><td class="cellrowborder" valign="top" width="19.439999999999998%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1433__a7d60b6cc3e1e4dfcadb2f71a4b554b03">col_name</p>
</td>
<td class="cellrowborder" valign="top" width="80.56%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1433__a5f54892bbecc42bf8830e346e0891a7a">Name of columns in a table. Column names contain letters, digits, and underscores (_).</p>
</td>
</tr>
<tr id="mrs_01_1433__r8746b8ab039b4d699910a29c3cc8ca46"><td class="cellrowborder" valign="top" width="19.439999999999998%" headers="mcps1.3.3.2.2.3.1.1 "><p id="mrs_01_1433__afd1931c3c83d42898750138877a69f59">changed_column_type</p>
</td>
<td class="cellrowborder" valign="top" width="80.56%" headers="mcps1.3.3.2.2.3.1.2 "><p id="mrs_01_1433__ac2ffb746750d415388cb1ed822223dbf">The change in the data type.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="mrs_01_1433__sa2d037069b6d4ccba70108f63dcd4897"><h4 class="sectiontitle">Usage Guidelines</h4><ul id="mrs_01_1433__ub5353c8fe89e43a2ae2bc152a88a73e3"><li id="mrs_01_1433__lc7875d7fca414e40ac453297953c1857">Change of decimal data type from lower precision to higher precision will only be supported for cases where there is no data loss.<p id="mrs_01_1433__a97f186b667e049ce92b62a768d58e57b"><a name="mrs_01_1433__lc7875d7fca414e40ac453297953c1857"></a><a name="lc7875d7fca414e40ac453297953c1857"></a>Example:</p>
<ul id="mrs_01_1433__u6be9f6dc71ff413abd29862252a243e6"><li id="mrs_01_1433__lf86b63e4136a40d6b733c43880f24d56"><strong id="mrs_01_1433__ac433970176ab4f73a2565bc14996a329">Invalid scenario</strong> - Change of decimal precision from (10,2) to (10,5) is not valid as in this case only scale is increased but total number of digits remain the same.</li><li id="mrs_01_1433__l000070d3283b41d38dc2ea1aca2ad660"><strong id="mrs_01_1433__a29cd47f728074aa0898b356999428cb0">Valid scenario</strong> - Change of decimal precision from (10,2) to (12,3) is valid as the total number of digits are increased by 2 but scale is increased only by 1 which will not lead to any data loss.</li></ul>
</li></ul>
<ul id="mrs_01_1433__ua54e8c3a4a6a49d79b221d6ed3c26782"><li id="mrs_01_1433__lee0490827a3048e29d1ff6e18f817079">The allowed range is 38,38 (precision, scale) and is a valid upper case scenario which is not resulting in data loss.</li></ul>
</div>
<div class="section" id="mrs_01_1433__s02de0ffe591b41d9b8435c03f68288f4"><h4 class="sectiontitle">Examples</h4><ul id="mrs_01_1433__u206f975e5e4a420ba1c44a77d4e2936c"><li id="mrs_01_1433__l87a9ea52385d4b30b5ff16fce001b664">Changing data type of column a1 from INT to BIGINT.<p id="mrs_01_1433__a7726335ac6b644f394c6aab6f7d2d170"><a name="mrs_01_1433__l87a9ea52385d4b30b5ff16fce001b664"></a><a name="l87a9ea52385d4b30b5ff16fce001b664"></a><b><span class="cmdname" id="mrs_01_1433__cmdname16180162492014">ALTER TABLE</span></b> <i><span class="varname" id="mrs_01_1433__vfe234c1df41740509685381f925849e4">test_db.carbon</span></i> <b><span class="cmdname" id="mrs_01_1433__cmdname1226172762020">CHANGE</span></b> <i><span class="varname" id="mrs_01_1433__v4708e7a863684f82ac730e242495c4ee">a1 a1 BIGINT</span></i>;</p>
</li><li id="mrs_01_1433__l12d34a7bbbf5418bb66e05a5965d5db4">Changing decimal precision of column a1 from 10 to 18.<p id="mrs_01_1433__aa4d853c6362d4fd382bb044772af9020"><a name="mrs_01_1433__l12d34a7bbbf5418bb66e05a5965d5db4"></a><a name="l12d34a7bbbf5418bb66e05a5965d5db4"></a><b><span class="cmdname" id="mrs_01_1433__cmdname8766230182012">ALTER TABLE</span></b> <i><span class="varname" id="mrs_01_1433__v937f0cf23c0848aa8ff921f9bbf9ba76">test_db.carbon</span></i> <b><span class="cmdname" id="mrs_01_1433__cmdname19501734142012">CHANGE</span></b> <i><span class="varname" id="mrs_01_1433__v12a5265b7032418392250bb23d0a434c">a1 a1 DECIMAL(18,2)</span></i>;</p>
</li></ul>
</div>
<div class="section" id="mrs_01_1433__sc1e4d30b28cb4317b1b12496c7d2b1d6"><h4 class="sectiontitle">System Response</h4><p id="mrs_01_1433__af0ecf2d950024408bc04ed4dedea0996">By running DESCRIBE command, the changed data type for the modified column is displayed.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_1424.html">DDL</a></div>
</div>
</div>