doc-exports/docs/dws/dev/dws_06_0178.html
Lu, Huayi e6fa411af0 DWS DEV 830.201 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2024-05-16 07:24:04 +00:00

133 lines
33 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<a name="EN-US_TOPIC_0000001188588956"></a><a name="EN-US_TOPIC_0000001188588956"></a>
<h1 class="topictitle1">CREATE TABLE AS</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001188588956__s0fdd420ded604c0f892a3500b3ce0302"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001188588956__ada208b4fb1c04da083c9b7e55ee35aad"><strong id="EN-US_TOPIC_0000001188588956__en-us_topic_0058965980_b8423527068546">CREATE TABLE AS</strong> creates a table based on the results of a query.</p>
<p id="EN-US_TOPIC_0000001188588956__a885cf628f17043e98990c62dd7650bb5">CREATE TABLE AS creates a table and fills it with the data returned by the SELECT statement. The columns in the new table match the names and data types of the output fields from the SELECT statement. Except that you can override the <strong id="EN-US_TOPIC_0000001188588956__b84235270684712">SELECT</strong> output column names by giving an explicit list of new column names.</p>
<p id="EN-US_TOPIC_0000001188588956__a037f53fa7a8a4d93b21049f80f30304d"><strong id="EN-US_TOPIC_0000001188588956__b842352706142327">CREATE TABLE AS</strong> queries once the source table and writes data in the new table. The query result view changes when the source table changes. In contrast, a view re-evaluates its defining <strong id="EN-US_TOPIC_0000001188588956__b84235270684755">SELECT</strong> statement whenever it is queried.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001188588956__s9b76e6b72cfb4e11a03d21f47baf83ac"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001188588956__u289f8cef9f9e4e2f938d9787e5be2888"><li id="EN-US_TOPIC_0000001188588956__l8f081f495db44664b2ba51c5020e474a">This command cannot be used to create a partitioned table.</li><li id="EN-US_TOPIC_0000001188588956__l97d9900e382d41749d583775054e624b">If an error occurs when you create a table, after the system is recovered, the system probably cannot automatically clear the created disk file whose size is not 0. This problem seldom occurs.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001188588956__s63ae91c2a3ea47fa85f3f0e835414bb7"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188588956__s6ad049064f164b29bf9b6224342c36a4"><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>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</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="w"> </span><span class="n">UNLOGGED</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">table_name</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="p">(</span><span class="k">column_name</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="p">]</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="err">{</span><span class="n">storage_parameter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">value</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="p">)</span><span class="w"> </span><span class="p">]</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">COMPRESS</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">NOCOMPRESS</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="n">DISTRIBUTE</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="n">REPLICATION</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">ROUNDROBIN</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="err">{</span><span class="w"> </span><span class="p">[</span><span class="n">HASH</span><span class="w"> </span><span class="p">]</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="err">}</span><span class="w"> </span><span class="err">}</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">COMMENT</span><span class="w"> </span><span class="p">[</span><span class="o">=</span><span class="p">]</span><span class="w"> </span><span class="s1">'text'</span><span class="w"> </span><span class="p">]</span>
<span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="n">query</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">NO</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="k">DATA</span><span class="w"> </span><span class="p">];</span>
</pre></div></td></tr></table></div>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001188588956__s13565e705b8046dba585cf1a28f07d28"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001188588956__u23c6b8a3f771432cabe3cd60ddba7bf2"><li id="EN-US_TOPIC_0000001188588956__l09667ea431d548c6b88d4195c7ea75d9"><strong id="EN-US_TOPIC_0000001188588956__aaa24b266960d4b719a8c019ac041a86a">UNLOGGED</strong><p id="EN-US_TOPIC_0000001188588956__ae3dfe737159a42b2923e6c3ff3d74e7e">Specifies that the table is created as an unlogged table. Data written to unlogged tables is not written to the write-ahead log, which makes them considerably faster than ordinary tables. However, they are not crash-safe: an unlogged table is automatically truncated after a crash or unclean shutdown. The contents of an unlogged table are also not replicated to standby servers. Any indexes created on an unlogged table are automatically unlogged as well.</p>
<ul id="EN-US_TOPIC_0000001188588956__u2a21b80f1b23426aac1e391d55f19930"><li id="EN-US_TOPIC_0000001188588956__l02abb25eb94f45aca730a0809a556139">Usage scenario: Unlogged tables do not ensure safe data. Users can back up data before using unlogged tables; for example, users should back up the data before a system upgrade.</li><li id="EN-US_TOPIC_0000001188588956__ldea2f43810ee41bca7c9756f526942b2">Troubleshooting: If data is missing in the indexes of unlogged tables due to some unexpected operations such as an unclean shutdown, users should re-create the indexes with errors.<div class="caution" id="EN-US_TOPIC_0000001188588956__note1110672620209"><span class="cautiontitle"><img src="public_sys-resources/caution_3.0-en-us.png"> </span><div class="cautionbody"><p id="EN-US_TOPIC_0000001188588956__p2462153318203">The UNLOGGED table uses no primary/standby mechanism. In the case of system faults or abnormal breakpoints, data loss may occur. Therefore, the UNLOGGED table cannot be used to store basic data.</p>
</div></div>
</li></ul>
</li><li id="EN-US_TOPIC_0000001188588956__l357155c3fff3489985f4099e8f252d6f"><strong id="EN-US_TOPIC_0000001188588956__a7572f77ad9824d6cbb8e743a7474a1d9">table_name</strong><p id="EN-US_TOPIC_0000001188588956__ab6fbbb0829ff4f6bbb2690ed22893f6e">Specifies the name of the table to be created.</p>
<p id="EN-US_TOPIC_0000001188588956__a0ac2b90bf5c94a8a8901899aecb3d5bb">Value range: a string. It must comply with the naming convention.</p>
</li><li id="EN-US_TOPIC_0000001188588956__l89f3829dc48b4bcdb23948e84784fd7a"><strong id="EN-US_TOPIC_0000001188588956__a19b113e3641f4dd984aa706f9d7bf24e">column_name</strong><p id="EN-US_TOPIC_0000001188588956__ac44abe640ee543e498ffd95adaa2dd2b">Specifies the name of a column to be created in the new table.</p>
<p id="EN-US_TOPIC_0000001188588956__aac1e7e9841e94a4db4a1d0eb8951ad49">Value range: a string. It must comply with the naming convention.</p>
</li><li id="EN-US_TOPIC_0000001188588956__lbc68ab36def34c64a8a75f2782e90c42"><strong id="EN-US_TOPIC_0000001188588956__aecf64a1871f14b4d8c578b36d408b710">WITH ( storage_parameter [= value] [, ... ] )</strong><p id="EN-US_TOPIC_0000001188588956__a3e74dd76f84b4f8f81bbfafbcb491d6e">Specifies an optional storage parameter for a table or an index. See details of parameters below.</p>
<ul id="EN-US_TOPIC_0000001188588956__ub9d872d3abbe45c7b1410c2d6380eb1d"><li id="EN-US_TOPIC_0000001188588956__l023ef61e2b83411aa540ad3a25288062">FILLFACTOR<p id="EN-US_TOPIC_0000001188588956__ae632bcf600514438bf1598bcf569b058"><a name="EN-US_TOPIC_0000001188588956__l023ef61e2b83411aa540ad3a25288062"></a><a name="l023ef61e2b83411aa540ad3a25288062"></a>The fillfactor of a table is a percentage between 10 and 100. When a smaller fillfactor is specified, <strong id="EN-US_TOPIC_0000001188588956__b2270294916957">INSERT</strong> operations pack table pages only to the indicated percentage. The remaining space on each page is reserved for updating rows on that page. This gives <strong id="EN-US_TOPIC_0000001188588956__b19751610427">UPDATE</strong> a chance to place the updated copy of a row on the same page, which is more efficient than placing it on a different page. For a table whose records are never updated, setting the fillfactor to 100 (complete packing) is the appropriate choice, but in heavily updated tables smaller fillfactors are appropriate. The parameter is only valid for rowstore tables.</p>
<p id="EN-US_TOPIC_0000001188588956__a339077a5434d4ae592ed257363204cf1">Value range: 10100</p>
<p id="EN-US_TOPIC_0000001188588956__p1828117226312">Default value: 100, indicating the fill is complete.</p>
</li><li id="EN-US_TOPIC_0000001188588956__le0f35b1781bf4dfba1ce7fbb80bc795d">ORIENTATION<p id="EN-US_TOPIC_0000001188588956__a4407e6637dfc4a63b6ac157e2670305a"><a name="EN-US_TOPIC_0000001188588956__le0f35b1781bf4dfba1ce7fbb80bc795d"></a><a name="le0f35b1781bf4dfba1ce7fbb80bc795d"></a>Valid value:</p>
<p id="EN-US_TOPIC_0000001188588956__abfcf9b40bd9643aa8255c3cbbfc67eb7"><strong id="EN-US_TOPIC_0000001188588956__b842352706112126">COLUMN</strong>: The data will be stored in columns.</p>
<p id="EN-US_TOPIC_0000001188588956__a6b46e9d887d847258c0493f3e3d82a8f"><strong id="EN-US_TOPIC_0000001188588956__b842352706112130">ROW</strong> (default value): The data will be stored in rows.</p>
</li><li id="EN-US_TOPIC_0000001188588956__ld8823673377542889d7f27f7d4a7fe1d">COMPRESSION<p id="EN-US_TOPIC_0000001188588956__a3038a29cb8354b31814bf44e1c8a344c"><a name="EN-US_TOPIC_0000001188588956__ld8823673377542889d7f27f7d4a7fe1d"></a><a name="ld8823673377542889d7f27f7d4a7fe1d"></a>Specifies the compression level of the table data. It determines the compression ratio and time. Generally, the higher the level of compression, the higher the ratio, the longer the time, and the lower the level of compression, the lower the ratio, the shorter the time. The actual compression ratio depends on the distribution characteristics of loading table data.</p>
<p id="EN-US_TOPIC_0000001188588956__a457a5f705047407ab0ea5b07697fdd1d">Valid value:</p>
<p id="EN-US_TOPIC_0000001188588956__a398993de667a4fa59d4e10b2058700e4">The valid values for column-store tables are <strong id="EN-US_TOPIC_0000001188588956__b323120311786">YES</strong>/<strong id="EN-US_TOPIC_0000001188588956__b823319312820">NO</strong> and <strong id="EN-US_TOPIC_0000001188588956__b723493111815">LOW</strong>/<strong id="EN-US_TOPIC_0000001188588956__b823513316818">MIDDLE</strong>/<strong id="EN-US_TOPIC_0000001188588956__b62367311688">HIGH</strong>, and the default is <strong id="EN-US_TOPIC_0000001188588956__b8237163115814">LOW</strong>.</p>
<div class="note" id="EN-US_TOPIC_0000001188588956__note141418320435"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188588956__p2507240560">Currently, row-store table compression is not supported.</p>
</div></div>
</li><li id="EN-US_TOPIC_0000001188588956__l38ce139667d04e5988d755bebddcf676">MAX_BATCHROW<p id="EN-US_TOPIC_0000001188588956__a2e88d178c53e473ea3ac01ba760ddc7b"><a name="EN-US_TOPIC_0000001188588956__l38ce139667d04e5988d755bebddcf676"></a><a name="l38ce139667d04e5988d755bebddcf676"></a>Specifies the maximum of a storage unit during data loading process. The parameter is only valid for column-store tables.</p>
<p id="EN-US_TOPIC_0000001188588956__p436617134568">Value range: 10000 to 60000</p>
<p id="EN-US_TOPIC_0000001188588956__a06b1298ccd8d430cb501be80bb1da025">Default value: <strong id="EN-US_TOPIC_0000001188588956__b523717494105922">60000</strong></p>
</li><li id="EN-US_TOPIC_0000001188588956__l086aa39d061947198ad34e4ef447eaf8">PARTIAL_CLUSTER_ROWS<p id="EN-US_TOPIC_0000001188588956__a5d994e078d444272b4bf8886495472c6"><a name="EN-US_TOPIC_0000001188588956__l086aa39d061947198ad34e4ef447eaf8"></a><a name="l086aa39d061947198ad34e4ef447eaf8"></a>Specifies the number of records to be partial cluster stored during data loading process. The parameter is only valid for column-store tables.</p>
<p id="EN-US_TOPIC_0000001188588956__ad4eabbd4cff64d3e8aa8ccf50da5814a">Value range: 600000 to 2147483647</p>
<p id="EN-US_TOPIC_0000001188588956__p02331858163611">Default value: 4,200,000</p>
</li><li id="EN-US_TOPIC_0000001188588956__li2613194271216">enable_delta<p id="EN-US_TOPIC_0000001188588956__p1761394219122"><a name="EN-US_TOPIC_0000001188588956__li2613194271216"></a><a name="li2613194271216"></a>Specifies whether to enable delta tables in column-store tables. The parameter is only valid for column-store tables.</p>
<p id="EN-US_TOPIC_0000001188588956__p561354210126">Default value: <strong id="EN-US_TOPIC_0000001188588956__b2367164110016">off</strong></p>
</li><li id="EN-US_TOPIC_0000001188588956__li5770191514236">COLVERSION<p id="EN-US_TOPIC_0000001188588956__p782817211266"><a name="EN-US_TOPIC_0000001188588956__li5770191514236"></a><a name="li5770191514236"></a>Specifies the version of the column-store format. You can switch between different storage formats.</p>
<p id="EN-US_TOPIC_0000001188588956__p79372062319">Valid value:</p>
<p id="EN-US_TOPIC_0000001188588956__p14943416142312"><strong id="EN-US_TOPIC_0000001188588956__b10445154515012">1.0</strong>: Each column in a column-store table is stored in a separate file. The file name is <strong id="EN-US_TOPIC_0000001188588956__b4445174516019">relfilenode.C1.0</strong>, <strong id="EN-US_TOPIC_0000001188588956__b12445114510014">relfilenode.C2.0</strong>, <strong id="EN-US_TOPIC_0000001188588956__b9446124520016">relfilenode.C3.0</strong>, or similar.</p>
<p id="EN-US_TOPIC_0000001188588956__p746104214618"><strong id="EN-US_TOPIC_0000001188588956__b9516850304">2.0</strong>: All columns of a column-store table are combined and stored in a file. The file is named <strong id="EN-US_TOPIC_0000001188588956__b1952119501908">relfilenode.C1.0</strong>.</p>
<p id="EN-US_TOPIC_0000001188588956__p11797193942314">Default value: <strong id="EN-US_TOPIC_0000001188588956__b11814231589">2.0</strong></p>
<div class="note" id="EN-US_TOPIC_0000001188588956__note324584962517"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188588956__p1566713589250">When creating a column-store table, set <strong id="EN-US_TOPIC_0000001188588956__b13557195215016">COLVERSION</strong> to <strong id="EN-US_TOPIC_0000001188588956__b8558195211014">2.0</strong>. Compared with the <strong id="EN-US_TOPIC_0000001188588956__b65584521017">1.0</strong> storage format, the performance is significantly improved:</p>
<ol id="EN-US_TOPIC_0000001188588956__ol141291029152617"><li id="EN-US_TOPIC_0000001188588956__li113062920266">The time required for creating a column-store wide table is significantly reduced.</li><li id="EN-US_TOPIC_0000001188588956__li19427204142616">In the Roach data backup scenario, the backup time is significantly reduced.</li><li id="EN-US_TOPIC_0000001188588956__li2178947192613">The build and catch up time is greatly reduced.</li><li id="EN-US_TOPIC_0000001188588956__li6836125342615">The occupied disk space decreases significantly.</li></ol>
</div></div>
</li></ul>
<ul id="EN-US_TOPIC_0000001188588956__ul1441110161432"><li id="EN-US_TOPIC_0000001188588956__li55111731143215">SKIP_FPI_HINT<p id="EN-US_TOPIC_0000001188588956__p185568515461"><a name="EN-US_TOPIC_0000001188588956__li55111731143215"></a><a name="li55111731143215"></a>Indicates whether to skip the hint bits operation when the full-page writes (FPW) log needs to be written during sequential scanning.</p>
<div class="p" id="EN-US_TOPIC_0000001188588956__p3172164012188">Default value: <strong id="EN-US_TOPIC_0000001188588956__b626738988105922">false</strong><div class="note" id="EN-US_TOPIC_0000001188588956__note177211636121818"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001188588956__p1721193631819">If <strong id="EN-US_TOPIC_0000001188588956__b83547431528">SKIP_FPI_HINT</strong> is set to <strong id="EN-US_TOPIC_0000001188588956__b735511431214">true</strong> and the checkpoint operation is performed on a table, no Xlog will be generated when the table is sequentially scanned. This applies to intermediate tables that are queried less frequently, reducing the size of Xlogs and improving query performance.</p>
</div></div>
</div>
</li></ul>
</li><li id="EN-US_TOPIC_0000001188588956__lab9c9a17d8f0403f9d84426279f285f9"><strong id="EN-US_TOPIC_0000001188588956__ac0426422545d4983a8b3a96e3b045617">COMPRESS / NOCOMPRESS</strong><p id="EN-US_TOPIC_0000001188588956__aba42e5b750af41a9859b91ff88aceb73">Specifies the keyword <strong id="EN-US_TOPIC_0000001188588956__b84235270685040">COMPRESS</strong> during the creation of a table, so that the compression feature is triggered in the case of a bulk <strong id="EN-US_TOPIC_0000001188588956__b522675911783">INSERT</strong> operation. If this feature is enabled, a scan is performed for all tuple data within the page to generate a dictionary and then the tuple data is compressed and stored. If <strong id="EN-US_TOPIC_0000001188588956__b6462771783">NOCOMPRESS</strong> is specified, the table is not compressed.</p>
<p id="EN-US_TOPIC_0000001188588956__a9d96c907488a4495baf3054ff5fd0760">Default value: <strong id="EN-US_TOPIC_0000001188588956__b842352706163420">NOCOMPRESS</strong>, tuple data is not compressed before storage.</p>
</li><li id="EN-US_TOPIC_0000001188588956__lb588c7b037104d2ba6ff196e603ec881"><strong id="EN-US_TOPIC_0000001188588956__a164b946dce364d46b355d94a69630511">DISTRIBUTE BY</strong><p id="EN-US_TOPIC_0000001188588956__a4eefbb5ac0754e6fa9aa3c632798b3e3">Specifies how the table is distributed or replicated between DNs.</p>
<ul id="EN-US_TOPIC_0000001188588956__u82055daa69a94860a072738092220fe2"><li id="EN-US_TOPIC_0000001188588956__le4a3336dc41b4181bc900a1d9b5b67d7"><strong id="EN-US_TOPIC_0000001188588956__b3582827154111">REPLICATION</strong>: Each row in the table exists on all DNs, that is, each DN has complete table data.</li><li id="EN-US_TOPIC_0000001188588956__li43301820418"><strong id="EN-US_TOPIC_0000001188588956__b96401092824823">ROUNDROBIN</strong>: Each row in the table is sent to each DN in sequence. This distribution policy prevents data skew. However, data distribution nodes are random. As a result, there is a higher probability that table redistribution is triggered during computing. This distribution policy is recommended for large tables with severe column skew. This value is supported only in 8.1.2 or later.</li><li id="EN-US_TOPIC_0000001188588956__la5b1c861b47c4cee8efcc05ff63c3a18"><strong id="EN-US_TOPIC_0000001188588956__b16583152754113">HASH (column_name)</strong>: Each row of the table will be placed into all the DNs based on the hash value of the specified column.</li></ul>
<div class="notice" id="EN-US_TOPIC_0000001188588956__n22e4f1c90ee24754ab6e29d2a074e000"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><ul id="EN-US_TOPIC_0000001188588956__u4050c4411af74df7a10ef6929023b62d"><li id="EN-US_TOPIC_0000001188588956__ladcedf396b1a4257a93fa36281ecf503">When <strong id="EN-US_TOPIC_0000001188588956__b175871327134110">DISTRIBUTE BY HASH (column_name)</strong> is specified, the primary key and its unique index must contain the <strong id="EN-US_TOPIC_0000001188588956__b7587142711412">column_name</strong> column.</li><li id="EN-US_TOPIC_0000001188588956__l9fac9f3c26c64ec2bc9e9c9937e09706">When <strong id="EN-US_TOPIC_0000001188588956__b15589172744112">DISTRIBUTE BY HASH (column_name)</strong> in a referenced table is specified, the foreign key of the reference table must contain the <strong id="EN-US_TOPIC_0000001188588956__b058911275411">column_name</strong> column.</li></ul>
</div></div>
<div class="p" id="EN-US_TOPIC_0000001188588956__p14251115041812">Default value: determined by the GUC parameter <strong id="EN-US_TOPIC_0000001188588956__b262247119">default_distribution_mode</strong><ul id="EN-US_TOPIC_0000001188588956__ul878364963015"><li id="EN-US_TOPIC_0000001188588956__li14783249163014">When <strong id="EN-US_TOPIC_0000001188588956__b1315020151716">default_distribution_mode</strong> is set to <strong id="EN-US_TOPIC_0000001188588956__b16151121513119">roundrobin</strong>, the default value of <strong id="EN-US_TOPIC_0000001188588956__b1615191514116">DISTRIBUTE BY</strong> is selected according to the following rules:<ol id="EN-US_TOPIC_0000001188588956__ol137381934837"><li id="EN-US_TOPIC_0000001188588956__li87381341531">If the primary key or unique constraint is included during table creation, hash distribution is selected. The distribution column is the column corresponding to the primary key or unique constraint.</li><li id="EN-US_TOPIC_0000001188588956__li0741558414">If the primary key or unique constraint is not included during table creation, round-robin distribution is selected.</li></ol>
</li><li id="EN-US_TOPIC_0000001188588956__li1645915396371">When <strong id="EN-US_TOPIC_0000001188588956__b057412428112">default_distribution_mode</strong> is set to <strong id="EN-US_TOPIC_0000001188588956__b145827421713">hash</strong>, the default value of <strong id="EN-US_TOPIC_0000001188588956__b115831642314">DISTRIBUTE BY</strong> is selected according to the following rules:<ol id="EN-US_TOPIC_0000001188588956__ol115828818381"><li id="EN-US_TOPIC_0000001188588956__li38741447517">If the primary key or unique constraint is included during table creation, hash distribution is selected. The distribution column is the column corresponding to the primary key or unique constraint.</li><li id="EN-US_TOPIC_0000001188588956__li990712591559">If the primary key or unique constraint is not included during table creation but there are columns whose data types can be used as distribution columns, hash distribution is selected. The distribution column is the first column whose data type can be used as a distribution column.</li><li id="EN-US_TOPIC_0000001188588956__li462574677">If the primary key or unique constraint is not included during table creation and no column whose data type can be used as a distribution column exists, round-robin distribution is selected.</li></ol>
</li></ul>
</div>
<div class="p" id="EN-US_TOPIC_0000001188588956__p613875615407">The following data types can be used as distribution columns:<ul id="EN-US_TOPIC_0000001188588956__ul8929105634111"><li id="EN-US_TOPIC_0000001188588956__li18929256194113">Integer types: <strong id="EN-US_TOPIC_0000001188588956__b186921757214">TINYINT</strong>, <strong id="EN-US_TOPIC_0000001188588956__b196921851927">SMALLINT</strong>, <strong id="EN-US_TOPIC_0000001188588956__b769315518219">INT</strong>, <strong id="EN-US_TOPIC_0000001188588956__b106939519218">BIGINT</strong>, and <strong id="EN-US_TOPIC_0000001188588956__b166941752028">NUMERIC/DECIMAL</strong></li><li id="EN-US_TOPIC_0000001188588956__li148954319420">Character types: <strong id="EN-US_TOPIC_0000001188588956__b6516091125">CHAR</strong>, <strong id="EN-US_TOPIC_0000001188588956__b195172091212">BPCHAR</strong>, <strong id="EN-US_TOPIC_0000001188588956__b19517494217">VARCHAR</strong>, <strong id="EN-US_TOPIC_0000001188588956__b8517991228">VARCHAR2</strong>, <strong id="EN-US_TOPIC_0000001188588956__b45183916212">NVARCHAR2</strong>, and <strong id="EN-US_TOPIC_0000001188588956__b2518109829">TEXT</strong></li><li id="EN-US_TOPIC_0000001188588956__li14231162624317">Date/time types: <strong id="EN-US_TOPIC_0000001188588956__b168299139213">DATE</strong>, <strong id="EN-US_TOPIC_0000001188588956__b4829413126">TIME</strong>, <strong id="EN-US_TOPIC_0000001188588956__b138297131225">TIMETZ</strong>, <strong id="EN-US_TOPIC_0000001188588956__b183071314213">TIMESTAMP</strong>, <strong id="EN-US_TOPIC_0000001188588956__b5830013828">TIMESTAMPTZ</strong>, <strong id="EN-US_TOPIC_0000001188588956__b19831141318215">INTERVAL</strong>, and <strong id="EN-US_TOPIC_0000001188588956__b1683191317215">SMALLDATETIME</strong></li></ul>
</div>
</li><li id="EN-US_TOPIC_0000001188588956__li15621123290"><strong id="EN-US_TOPIC_0000001188588956__b7603185683113">COMMENT [=] 'text'</strong><p id="EN-US_TOPIC_0000001188588956__p4773051103117">The <strong id="EN-US_TOPIC_0000001188588956__b65380281007">COMMENT</strong> clause can specify table comments during table creation.</p>
</li><li id="EN-US_TOPIC_0000001188588956__l286a2d1b0c944787ab9cc667436e4354"><strong id="EN-US_TOPIC_0000001188588956__a2b7dfb2c940c4db78e7c42b2afe759eb">AS query</strong><p id="EN-US_TOPIC_0000001188588956__a47ee631a5bf0400ca6160aa14bf749dd">Indicates a <strong id="EN-US_TOPIC_0000001188588956__b20068529164441">SELECT</strong> or <strong id="EN-US_TOPIC_0000001188588956__b46399033164441">VALUES</strong> command, or an <strong id="EN-US_TOPIC_0000001188588956__b14938113164441">EXECUTE</strong> command that runs a prepared <strong id="EN-US_TOPIC_0000001188588956__b225290164441">SELECT</strong>, or <strong id="EN-US_TOPIC_0000001188588956__b2027613164441">VALUES</strong> query.</p>
</li><li id="EN-US_TOPIC_0000001188588956__laf3b09d8584e4d1492e79ca0972083a2"><strong id="EN-US_TOPIC_0000001188588956__a79691f9f5301428ea4a772e6fbd69464">[ WITH [ NO ] DATA ]</strong><p id="EN-US_TOPIC_0000001188588956__aa99134cd66cd416aad68e926ae0554a8">Specifies whether the data produced by the query should be copied into the new table. By default, the data is copied. If the <strong id="EN-US_TOPIC_0000001188588956__b184341529165518">NO</strong> parameter is used, the data is not copied.</p>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001188588956__sa565fe58bd814741b0980a000dfa388d"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001188588956__p1644613456509">Create the <strong id="EN-US_TOPIC_0000001188588956__b1186546611">CUSTOMER</strong> table:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188588956__screen97220431583"><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>
<span class="normal">8</span>
<span class="normal">9</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">DROP</span><span class="w"> </span><span class="k">TABLE</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="n">CUSTOMER</span><span class="p">;</span>
<span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">CUSTOMER</span>
<span class="p">(</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_CUSTKEY</span><span class="w"> </span><span class="nb">BIGINT</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="k">CONSTRAINT</span><span class="w"> </span><span class="n">C_CUSTKEY_pk</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="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NAME</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">25</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_ADDRESS</span><span class="w"> </span><span class="nb">VARCHAR</span><span class="p">(</span><span class="mi">40</span><span class="p">)</span><span class="w"> </span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">C_NATIONKEY</span><span class="w"> </span><span class="nb">INT</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="k">CHECK</span><span class="w"> </span><span class="p">(</span><span class="n">C_NATIONKEY</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span>
<span class="p">)</span>
<span class="n">DISTRIBUTE</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="n">HASH</span><span class="p">(</span><span class="n">C_CUSTKEY</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188588956__p1672541810264">Create the <strong id="EN-US_TOPIC_0000001188588956__b1150021217117">store_returns_t1</strong> table and insert numbers that are greater than 4795 in the <strong id="EN-US_TOPIC_0000001188588956__b14501121210113">CUSTOMER</strong> column of the <strong id="EN-US_TOPIC_0000001188588956__b19501101210116">CUSTOMER</strong> table:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188588956__screen16323212122812"><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">TABLE</span><span class="w"> </span><span class="n">store_returns_t1</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="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">CUSTOMER</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">C_CUSTKEY</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">4795</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001188588956__p1372510184267">Copy <strong id="EN-US_TOPIC_0000001188588956__b99207011233640">store_returns</strong> to create the <strong id="EN-US_TOPIC_0000001188588956__b27599506833640">store_returns_t2</strong> table:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001188588956__screen153492051288"><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">TABLE</span><span class="w"> </span><span class="n">store_returns_t2</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span><span class="k">table</span><span class="w"> </span><span class="n">store_returns</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001188588956__s911fcc5b711541e08d0bf164004af913"><h4 class="sectiontitle">Helpful Links</h4><p id="EN-US_TOPIC_0000001188588956__a5b3c026b1ef245cab2ba7ee731e197bd"><a href="dws_06_0177.html">CREATE TABLE</a>, <a href="dws_06_0238.html">SELECT</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>