doc-exports/docs/dws/tool/dws_16_0094.html
Lu, Huayi 27019c2991 DWS TOOL 830.201 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
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:35:25 +00:00

116 lines
10 KiB
HTML

<a name="EN-US_TOPIC_0000001819336149"></a><a name="EN-US_TOPIC_0000001819336149"></a>
<h1 class="topictitle1">DELETE</h1>
<div id="body8662426"><p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p94711529113616"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b14088975753199">DELETE</strong> (<a href="dws_16_0054.html#EN-US_TOPIC_0000001772696108">short key</a> abbreviated as <strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b14016280063199">DEL</strong>) is an ANSI-compliant SQL syntax operator used to delete existing records from a table. DSC supports the Teradata <strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b9504090563199">DELETE</strong> statement and its short key <strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b14433022033199">DEL</strong>. DELETE statements that do not contain the WHERE clause are migrated to TRUNCATE in GaussDB T, GaussDB A, and GaussDB(DWS). Use the <a href="dws_16_0014.html#EN-US_TOPIC_0000001819416085__en-us_topic_0000001706224349_en-us_topic_0000001432527901_li2884123118322">deleteToTruncate</a> parameter to enable or disable this behavior.</p>
<p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p32941914154418"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b6769122343199">Input: DELETE</strong></p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_screen829401434413"><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="n">DEL</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">tab1</span>
<span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="mi">10</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p729691413446"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b1075718517588">Output</strong></p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_screen10296114144415"><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">DELETE</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">tab1</span>
<span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="mi">10</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p663419862610"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b7612270983199">Input: DELETE without WHERE - Migrated to TRUNCATE</strong> <strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b5327596083199">if deletetoTruncate</strong><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b12340922593199">=TRUE</strong></p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_screen1163478122619"><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">DELETE</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="err">${</span><span class="n">schemaname</span><span class="err">}</span><span class="w"> </span><span class="p">.</span><span class="w"> </span><span class="ss">&quot;tablename&quot;</span><span class="w"> </span><span class="k">ALL</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p3635168202613"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b2764831599">Output</strong></p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_screen463518815263"><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></pre></div></td><td class="code"><div><pre><span></span><span class="k">TRUNCATE</span>
<span class="w"> </span><span class="k">TABLE</span>
<span class="w"> </span><span class="err">${</span><span class="n">schemaname</span><span class="err">}</span><span class="w"> </span><span class="p">.</span><span class="w"> </span><span class="ss">&quot;tablename&quot;</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p1806135442714"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b7221919603199">In DELETE, the same table is used in DELETE and FROM clauses with / without WHERE clause</strong></p>
<p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p1236065432111"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b5981352162114">Input</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_screen22433716226">DELETE DP_TMP.M_P_TX_SCV_REMAINING_PARTY
FROM DP_TMP.M_P_TX_SCV_REMAINING_PARTY ALL ;
---
DELETE DP_VMCTLFW.CTLFW_Process_Id
FROM DP_VMCTLFW.CTLFW_Process_Id
WHERE (Process_Name = :_spVV2 )
AND (Process_Id NOT IN (SELECT MAX(Process_Id )(NAMED Process_Id )
FROM DP_VMCTLFW.CTLFW_Process_Id
WHERE Process_Name = :_spVV2 )
);
---
DELETE CPID
FROM DP_VMCTLFW.CTLFW_Process_Id AS CPID
WHERE (Process_Name = :_spVV2 )
AND (Process_Id NOT IN (SELECT MAX(Process_Id )(NAMED Process_Id )
FROM DP_VMCTLFW.CTLFW_Process_Id
WHERE Process_Name = :_spVV2 )
);</pre>
<p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p132321458132119"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b13901811227">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_screen664610148225">DELETE FROM DP_TMP.M_P_TX_SCV_REMAINING_PARTY;
---
DELETE FROM DP_VMCTLFW.CTLFW_Process_Id
WHERE (Process_Name = :_spVV2 )
AND (Process_Id NOT IN (SELECT MAX(Process_Id )(NAMED Process_Id )
FROM DP_VMCTLFW.CTLFW_Process_Id
WHERE Process_Name = :_spVV2 )
);
---
DELETE FROM DP_VMCTLFW.CTLFW_Process_Id AS CPID
WHERE (Process_Name = :_spVV2 )
AND (Process_Id NOT IN (SELECT MAX(Process_Id )(NAMED Process_Id )
FROM DP_VMCTLFW.CTLFW_Process_Id
WHERE Process_Name = :_spVV2 )
);</pre>
<div class="section" id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_section789103613470"><h4 class="sectiontitle">DELETE table_alias FROM table</h4><p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p19691637114715"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b2853154517518">Input</strong></p>
</div>
<pre class="screen" id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_screen16890824144711">SQL_Detail10124.sql
delete a
from ${BRTL_DCOR}.BRTL_CS_POT_CUST_UMPAY_INF_S as a
where a.DW_Snsh_Dt = cast('${v_Trx_Dt}' as date format 'yyyy-mm-dd')
and a.DW_Job_Seq = 1 ;
was migrated as below:
DELETE FROM
BRTL_DCOR.BRTL_CS_POT_CUST_UMPAY_INF_S AS a
USING
WHERE a.DW_Snsh_Dt = CAST( lv_mig_v_Trx_Dt AS DATE )
AND a.DW_Job_Seq = 1 ;
SQL_Detail10449.sql
delete a
from ${BRTL_DCOR}.BRTL_EM_YISHITONG_USR_INF as a
where a.DW_Job_Seq = 1 ;
was migrated as below:
DELETE FROM
BRTL_DCOR.BRTL_EM_YISHITONG_USR_INF AS a
USING
WHERE a.DW_Job_Seq = 1 ;
SQL_Detail5742.sql
delete a
from ${BRTL_DCOR}.BRTL_PD_FP_NAV_ADT_INF as a;
was migrated as
DELETE a
FROM
BRTL_DCOR.BRTL_PD_FP_NAV_ADT_INF AS a ;</pre>
<p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p1277913121474"><strong id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_b206911442356">Output</strong></p>
<pre class="screen" id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_screen1347116280473">SQL_Detail10124.sql
delete from ${BRTL_DCOR}.BRTL_CS_POT_CUST_UMPAY_INF_S as a
where a.DW_Snsh_Dt = cast('${v_Trx_Dt}' as date format 'yyyy-mm-dd')
and a.DW_Job_Seq = 1 ;
SQL_Detail10449.sql
delete from ${BRTL_DCOR}.BRTL_EM_YISHITONG_USR_INF as a
where a.DW_Job_Seq = 1 ;
SQL_Detail5742.sql
delete from ${BRTL_DCOR}.BRTL_PD_FP_NAV_ADT_INF as a;</pre>
<p id="EN-US_TOPIC_0000001819336149__en-us_topic_0000001706104649_en-us_topic_0000001434790473_p1065311150511"></p>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_16_0084.html">Data Manipulation Language (DML)</a></div>
</div>
</div>