forked from docs/doc-exports
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>
307 lines
42 KiB
HTML
307 lines
42 KiB
HTML
<a name="EN-US_TOPIC_0000001233430195"></a><a name="EN-US_TOPIC_0000001233430195"></a>
|
|
|
|
<h1 class="topictitle1">LOCK</h1>
|
|
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001233430195__secc275dadf0d45e5a345ba787b8ce30f"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001233430195__af1c1e6bac5774044884a4e7887a1fff5"><strong id="EN-US_TOPIC_0000001233430195__en-us_topic_0085032098_b5959255010396">LOCK TABLE</strong> obtains a table-level lock.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__a6b1d14a0b44a48faa45cc3b8825397e8">When the lock for commands referencing a table is automatically acquired, <span id="EN-US_TOPIC_0000001233430195__text2131658412">GaussDB(DWS)</span> always uses the lock mode with minimum constraints. Use <strong id="EN-US_TOPIC_0000001233430195__en-us_topic_0085032098_b42746080183935">LOCK</strong> if users need a more strict lock mode. For example, suppose an application runs a transaction at the <strong id="EN-US_TOPIC_0000001233430195__b578502513018">Read Committed</strong> isolation level and needs to ensure that data in a table remains stable in the duration of the transaction. To achieve this, you could obtain <strong id="EN-US_TOPIC_0000001233430195__en-us_topic_0040045543_b20283862103857">SHARE</strong> lock mode over the table before the query. This will prevent concurrent data changes and ensure subsequent reads of the table see a stable view of committed data. It is because the <strong id="EN-US_TOPIC_0000001233430195__b48337033103857">SHARE</strong> lock mode conflicts with the <strong id="EN-US_TOPIC_0000001233430195__b32380114103857">ROW EXCLUSIVE</strong> lock acquired by writers, and your <strong id="EN-US_TOPIC_0000001233430195__b22985570103857">LOCK TABLE name IN SHARE MODE</strong> statement will wait until any concurrent holders of <strong id="EN-US_TOPIC_0000001233430195__b5543538103857">ROW EXCLUSIVE</strong> mode locks commit or roll back. Therefore, once you obtain the lock, there are no uncommitted writes outstanding; furthermore none can begin until you release the lock.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233430195__sf9eefb58a1ce405fb2a6863e50a3ef9d"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001233430195__u4d2844876e9f46cba2c78becb18ae515"><li id="EN-US_TOPIC_0000001233430195__l68fd7cc558bf4562973c0e6367ffa254"><strong id="EN-US_TOPIC_0000001233430195__b13350347184011">LOCK TABLE</strong> is useless outside a transaction block: the lock would remain held only to the completion of the statement. If <strong id="EN-US_TOPIC_0000001233430195__b84235270615938">LOCK TABLE</strong> is out of any transaction block, an error is reported.</li><li id="EN-US_TOPIC_0000001233430195__l9af822d99b5d486fa031c125573e8385">If no lock mode is specified, then <strong id="EN-US_TOPIC_0000001233430195__b10140957103929">ACCESS EXCLUSIVE</strong>, the most restrictive mode, is used.</li><li id="EN-US_TOPIC_0000001233430195__l50300fd05adc4133821fc6fb035f102b">LOCK TABLE ... IN ACCESS SHARE MODE requires the <strong id="EN-US_TOPIC_0000001233430195__b84235270611446">SELECT</strong> permission on the target table. All other forms of <strong id="EN-US_TOPIC_0000001233430195__b29940201103929">LOCK</strong> require table-level <strong id="EN-US_TOPIC_0000001233430195__b1026358103929">UPDATE</strong> and/or the <strong id="EN-US_TOPIC_0000001233430195__b9237230103929">DELETE</strong> permission.</li><li id="EN-US_TOPIC_0000001233430195__l013cd77dce314591861fda5461eca698">There is no <strong id="EN-US_TOPIC_0000001233430195__b10018151103929">UNLOCK TABLE</strong> command. Locks are always released at transaction end.</li><li id="EN-US_TOPIC_0000001233430195__l12edee3375454c7a9d650d88fec1bc79"><strong id="EN-US_TOPIC_0000001233430195__b9380343184023">LOCK TABLE</strong> only deals with table-level locks, and so the mode names involving <strong id="EN-US_TOPIC_0000001233430195__b29513943103929">ROW</strong> are all misnomers. These mode names should generally be read as indicating the intention of the user to acquire row-level locks within the locked table. Also, <strong id="EN-US_TOPIC_0000001233430195__en-us_topic_0085032098_b64298897103929">ROW EXCLUSIVE</strong> mode is a shareable table lock. Keep in mind that all the lock modes have identical semantics so far as <strong id="EN-US_TOPIC_0000001233430195__en-us_topic_0085032098_b41819165103929">LOCK TABLE</strong> is concerned, differing only in the rules about which modes conflict with which. For details about the rules, see <a href="#EN-US_TOPIC_0000001233430195__tec3c848278c344f9a15c8ab751ad98d7">Table 1</a>.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233430195__s51f69d8bcfe34440bd5456b8286cb7ec"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430195__s64b55902ede44489a2bdd6eeea5bf399"><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">LOCK</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">TABLE</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">ONLY</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...]</span><span class="o">|</span><span class="w"> </span><span class="err">{</span><span class="n">name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="o">*</span><span class="w"> </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="err">}</span>
|
|
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">IN</span><span class="w"> </span><span class="err">{</span><span class="k">ACCESS</span><span class="w"> </span><span class="k">SHARE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">ROW</span><span class="w"> </span><span class="k">SHARE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">ROW</span><span class="w"> </span><span class="k">EXCLUSIVE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">SHARE</span><span class="w"> </span><span class="k">UPDATE</span><span class="w"> </span><span class="k">EXCLUSIVE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">SHARE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">SHARE</span><span class="w"> </span><span class="k">ROW</span><span class="w"> </span><span class="k">EXCLUSIVE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">EXCLUSIVE</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">ACCESS</span><span class="w"> </span><span class="k">EXCLUSIVE</span><span class="err">}</span><span class="w"> </span><span class="k">MODE</span><span class="w"> </span><span class="p">]</span>
|
|
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">NOWAIT</span><span class="w"> </span><span class="p">];</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233430195__sd41f320125df4d189e342d377733aa28"><h4 class="sectiontitle">Parameter Description</h4>
|
|
<div class="tablenoborder"><a name="EN-US_TOPIC_0000001233430195__tec3c848278c344f9a15c8ab751ad98d7"></a><a name="tec3c848278c344f9a15c8ab751ad98d7"></a><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233430195__tec3c848278c344f9a15c8ab751ad98d7" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Lock mode conflicts</caption><thead align="left"><tr id="EN-US_TOPIC_0000001233430195__re62255242b034ae287ea38ae49d6810a"><th align="left" class="cellrowborder" valign="top" width="11.111111111111112%" id="mcps1.3.4.2.2.10.1.1"><p id="EN-US_TOPIC_0000001233430195__a4ff167915bc44db8bade47929ab9dd80">Requested Lock Mode/Current Lock Mode</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="11.111111111111112%" id="mcps1.3.4.2.2.10.1.2"><p id="EN-US_TOPIC_0000001233430195__a815c5a7aafbc4963bd1b784e69c5dedb">ACCESS SHARE</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="11.111111111111112%" id="mcps1.3.4.2.2.10.1.3"><p id="EN-US_TOPIC_0000001233430195__addeace858ab245f4914e914d9c8fd2e9">ROW SHARE</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="11.111111111111112%" id="mcps1.3.4.2.2.10.1.4"><p id="EN-US_TOPIC_0000001233430195__ac03b638462e346378d7b1e34779f80ae">ROW EXCLUSIVE</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="11.111111111111112%" id="mcps1.3.4.2.2.10.1.5"><p id="EN-US_TOPIC_0000001233430195__a2013bce63bf24cc8951bdb1662c9042a">SHARE UPDATE EXCLUSIVE</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="11.111111111111112%" id="mcps1.3.4.2.2.10.1.6"><p id="EN-US_TOPIC_0000001233430195__a1614623de84c4d38a8bd2ace69e9d99c">SHARE</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="11.111111111111112%" id="mcps1.3.4.2.2.10.1.7"><p id="EN-US_TOPIC_0000001233430195__a4552f3d4bcc848fabf9e4f333cd048cc">SHARE ROW EXCLUSIVE</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="11.111111111111112%" id="mcps1.3.4.2.2.10.1.8"><p id="EN-US_TOPIC_0000001233430195__a5670f06dfb2444b29a14f7c6e75197ae">EXCLUSIVE</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="11.111111111111112%" id="mcps1.3.4.2.2.10.1.9"><p id="EN-US_TOPIC_0000001233430195__a0691b3f7c2d7454b817077c0f5e837d5">ACCESS EXCLUSIVE</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001233430195__rd459bf964e6245989727d5ac235c902e"><td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.1 "><p id="EN-US_TOPIC_0000001233430195__a86f93d698d2840ec888ef730a05cbd3a">ACCESS SHARE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.2 "><p id="EN-US_TOPIC_0000001233430195__ad41f1449da704d828a8dcc205e5a9358">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.3 "><p id="EN-US_TOPIC_0000001233430195__a473145a94f31448eb0281f0ead8ec1f4">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.4 "><p id="EN-US_TOPIC_0000001233430195__af758125ed2a74e699f75b66dd6202c6b">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.5 "><p id="EN-US_TOPIC_0000001233430195__aa2c9eac45826401b80366ae7c894b7cc">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.6 "><p id="EN-US_TOPIC_0000001233430195__a20fa6451966442568a041e06e6be02c1">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.7 "><p id="EN-US_TOPIC_0000001233430195__ad4947f9a73534e7b9a43d268af89e552">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.8 "><p id="EN-US_TOPIC_0000001233430195__a9ebe196ed6d6427faf4a35b859803361">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.9 "><p id="EN-US_TOPIC_0000001233430195__a50363cfc97c047b7b145ad6fe0b3d840">X</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430195__r97b0eec40b424ed58c2cc49b08da52e2"><td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.1 "><p id="EN-US_TOPIC_0000001233430195__adcd818e2fe95444abc63f8e48c3b2fab">ROW SHARE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.2 "><p id="EN-US_TOPIC_0000001233430195__af4640253b568448d97a01d264351d20b">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.3 "><p id="EN-US_TOPIC_0000001233430195__a3af0a0a5bad24e6ea2807bdda2244541">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.4 "><p id="EN-US_TOPIC_0000001233430195__ae3df7421e626422b963933ab860fc6e1">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.5 "><p id="EN-US_TOPIC_0000001233430195__a11767e0a0bbc4a31ad0b41ff34a5669d">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.6 "><p id="EN-US_TOPIC_0000001233430195__a92bf226349354b2cac554ebe368f637c">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.7 "><p id="EN-US_TOPIC_0000001233430195__a59f8aaad96de43ca9220fb6a2fd6ae68">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.8 "><p id="EN-US_TOPIC_0000001233430195__a081c0760feee4e83a33ab5999295d409">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.9 "><p id="EN-US_TOPIC_0000001233430195__a5760137abe2e43e4938e920bb67ff42a">X</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430195__r375b35fcb8304f6aa5cd513565d7ebfb"><td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.1 "><p id="EN-US_TOPIC_0000001233430195__af72653b3dd7e4feca6ed445ae5955dab">ROW EXCLUSIVE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.2 "><p id="EN-US_TOPIC_0000001233430195__aeacfdaf7d0ad42b3b55945e86892ecb1">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.3 "><p id="EN-US_TOPIC_0000001233430195__a5140fca54ef44c42aa381d874228fe11">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.4 "><p id="EN-US_TOPIC_0000001233430195__ab70501b6903447e38821bb049c7eafcc">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.5 "><p id="EN-US_TOPIC_0000001233430195__a1e2372efe2444628a14adae5f96dee97">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.6 "><p id="EN-US_TOPIC_0000001233430195__a015010fb4b5945f3a1fb458f18425f1b">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.7 "><p id="EN-US_TOPIC_0000001233430195__a9526e5e2417f414ca9b4892910d324a1">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.8 "><p id="EN-US_TOPIC_0000001233430195__a83b926fad30743d09887951d88880412">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.9 "><p id="EN-US_TOPIC_0000001233430195__a68dfd6da36864bf79518d047cad399b4">X</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430195__rc8f85543b5754a5d9cbdf8ea0a4acc7b"><td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.1 "><p id="EN-US_TOPIC_0000001233430195__a0f08ba0db1ba43aba98d04c6f63a8fb3">SHARE UPDATE EXCLUSIVE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.2 "><p id="EN-US_TOPIC_0000001233430195__a745235e8b2ee4cf090f63331e5cd83c2">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.3 "><p id="EN-US_TOPIC_0000001233430195__a75bc0709636c4424aabfdfde656f4abf">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.4 "><p id="EN-US_TOPIC_0000001233430195__ad8a81978255a452e99d3379465889700">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.5 "><p id="EN-US_TOPIC_0000001233430195__ae167ca3d219449749135b2bd1ff658b8">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.6 "><p id="EN-US_TOPIC_0000001233430195__a855ac35af79e4d36b00315ce08498d91">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.7 "><p id="EN-US_TOPIC_0000001233430195__a82d97a3804874c25a09e31a6fa795882">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.8 "><p id="EN-US_TOPIC_0000001233430195__abfbdb9abf0ae41289c897a7730b63ba5">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.9 "><p id="EN-US_TOPIC_0000001233430195__ae721c026e5e54ad28602fdb401aa0f6b">X</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430195__r1021bfc6ce4943dcbda3565d01778d76"><td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.1 "><p id="EN-US_TOPIC_0000001233430195__abb00d86aff8e4002b6ca7cd17207591a">SHARE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.2 "><p id="EN-US_TOPIC_0000001233430195__a3a93d5aa6a8c4ac984d1f4939d5e7524">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.3 "><p id="EN-US_TOPIC_0000001233430195__a4e8d9be1411d4534bd6dd91d61ace163">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.4 "><p id="EN-US_TOPIC_0000001233430195__a5c3275589836443298ec02cdb34f9287">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.5 "><p id="EN-US_TOPIC_0000001233430195__a70c9bb04f6e846c0bf711b2bf893f699">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.6 "><p id="EN-US_TOPIC_0000001233430195__a080200cb62dd42f59b0cb80feb910536">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.7 "><p id="EN-US_TOPIC_0000001233430195__abf9fa217bb614b55860a7f1c26f2e698">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.8 "><p id="EN-US_TOPIC_0000001233430195__aa9fc024501bf4d128a0040ad9b800799">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.9 "><p id="EN-US_TOPIC_0000001233430195__ad6249f10dbbd4b6ea6dd828406199fdd">X</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430195__r1e606e7b9d614c508149a06ee003f7ca"><td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.1 "><p id="EN-US_TOPIC_0000001233430195__a583bbafa61e34530a8935b8486d3aa25">SHARE ROW EXCLUSIVE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.2 "><p id="EN-US_TOPIC_0000001233430195__a773d72276f8244eabb813943d674b8b1">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.3 "><p id="EN-US_TOPIC_0000001233430195__a842cd0f53a4e41188023878d390f10e4">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.4 "><p id="EN-US_TOPIC_0000001233430195__a1bd646ec6de24086a393df1082093a8f">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.5 "><p id="EN-US_TOPIC_0000001233430195__a8dcedc41fdc742738e2078bbaa78093b">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.6 "><p id="EN-US_TOPIC_0000001233430195__a28187f915b9d461dbe2b455133349e64">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.7 "><p id="EN-US_TOPIC_0000001233430195__a4c00bd5291a542869e7987b0068465ee">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.8 "><p id="EN-US_TOPIC_0000001233430195__a2b54835664154db2bafb796d31c32b00">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.9 "><p id="EN-US_TOPIC_0000001233430195__a0d526e22113844609b22fdba302b0960">X</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430195__r5c7c3455618841d09a836a9835df9a94"><td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.1 "><p id="EN-US_TOPIC_0000001233430195__a506cbe83d9b04a65a64a7b85525281fa">EXCLUSIVE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.2 "><p id="EN-US_TOPIC_0000001233430195__ac47c1ceb27154c64bf5be46407acdc9c">-</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.3 "><p id="EN-US_TOPIC_0000001233430195__a7c8ffbd83fa24ca68a27155e0e2bc5ec">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.4 "><p id="EN-US_TOPIC_0000001233430195__aef10acc737984e67af0a3dfce99e6676">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.5 "><p id="EN-US_TOPIC_0000001233430195__ad156d01aa44b48cda82dfe5349715eab">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.6 "><p id="EN-US_TOPIC_0000001233430195__a946fdc91070d43769c65fbc7db1cee22">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.7 "><p id="EN-US_TOPIC_0000001233430195__a6ffab005b53c4528ad72acdc4d073eb8">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.8 "><p id="EN-US_TOPIC_0000001233430195__a790493265b1a4cb3b3d4196f47b01858">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.9 "><p id="EN-US_TOPIC_0000001233430195__ad0fa91730f5944df8d2901dfd4608899">X</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001233430195__r9f818fb0092f47e583ac704cae8e91bd"><td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.1 "><p id="EN-US_TOPIC_0000001233430195__a4c01802b0ad749e4b4d607d1c6226836">ACCESS EXCLUSIVE</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.2 "><p id="EN-US_TOPIC_0000001233430195__ac48a0f2b417c4d25b65406afc7e4a1fe">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.3 "><p id="EN-US_TOPIC_0000001233430195__a3918eed528e24ecc89c5881ad3d37860">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.4 "><p id="EN-US_TOPIC_0000001233430195__a9c6d9f01e7f64166b4c83f53d1ae3560">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.5 "><p id="EN-US_TOPIC_0000001233430195__aa8ab6c60859f4a6491f24fc9720bd5a0">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.6 "><p id="EN-US_TOPIC_0000001233430195__a790339bb6f3d40a185a4c2963adb5f8f">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.7 "><p id="EN-US_TOPIC_0000001233430195__a2d417c9b64aa4d3a8c01dfd3be643f70">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.8 "><p id="EN-US_TOPIC_0000001233430195__a067d1cba08a147d2b49c14e6e593ffbf">X</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.111111111111112%" headers="mcps1.3.4.2.2.10.1.9 "><p id="EN-US_TOPIC_0000001233430195__a296cc060a1a1438b97448f6a3670aca7">X</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001233430195__ab1c489b11c6c45c09bafb0d8e5af18a5"><strong id="EN-US_TOPIC_0000001233430195__b842352706151327">LOCK</strong> parameters are as follows:</p>
|
|
<ul id="EN-US_TOPIC_0000001233430195__u44cb9d7c744c475e94a94548bd7e2293"><li id="EN-US_TOPIC_0000001233430195__lc4d3b29bca214421a879891577b725fc"><strong id="EN-US_TOPIC_0000001233430195__a24f648d7d29d46dc82120c1b0ec6a4b1">name</strong><p id="EN-US_TOPIC_0000001233430195__a455b47425dc444ad8b8da356ba119cc6">The name (optionally schema-qualified) of an existing table to lock.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__aac98498f89ca44f387cf2fc9f3369c98">The tables are locked one-by-one in the order specified in the <strong id="EN-US_TOPIC_0000001233430195__b63540875183935">LOCK TABLE</strong> command.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__a11b00975dc4c4c078ce48c3e4c54c9a5">Value range: an existing table name</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__l8bec973bb9bb46e797c145c46b7632e5"><strong id="EN-US_TOPIC_0000001233430195__a41cabc8426524fe888ab474d16b3eff9">ONLY</strong><p id="EN-US_TOPIC_0000001233430195__a1546ce5095974da9bcf8e6245e12da89"><strong id="EN-US_TOPIC_0000001233430195__b60504204183935">Only</strong> locks only this table. If <strong id="EN-US_TOPIC_0000001233430195__b7666932183935">Only</strong> is not specified, this table and all its sub-tables are locked.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__l028de87d006a494aac97ddc447614025"><strong id="EN-US_TOPIC_0000001233430195__ab43c4fb509984e14acf937730265a2f3">ACCESS SHARE</strong><p id="EN-US_TOPIC_0000001233430195__a7f8a6d27520540a2a1076bc476c7455b"><strong id="EN-US_TOPIC_0000001233430195__b0469739102513">ACCESS SHARE</strong> allows only read operations on a table. In general, any SQL statements that only read a table and do not modify it will acquire this lock mode. The <strong id="EN-US_TOPIC_0000001233430195__b55414293183935">SELECT</strong> command acquires a lock of this mode on referenced tables.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__ldfe125c54faa4fcdb0ff5c59c05fb4ce"><strong id="EN-US_TOPIC_0000001233430195__acc1e750f95a54a16af0d5735e2841df0">ROW SHARE</strong><p id="EN-US_TOPIC_0000001233430195__a53fd059dbf0b405bbce30e446e324ab2"><strong id="EN-US_TOPIC_0000001233430195__b126977234433715">ROW SHARE</strong> allows concurrent read of a table but does not allow any other operations on the table.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__a0e8b2eb5578c40c2a3fa577fa09ce992"><strong id="EN-US_TOPIC_0000001233430195__b45118082833715">SELECT FOR UPDATE</strong> and <strong id="EN-US_TOPIC_0000001233430195__b3802849933715">SELECT FOR SHARE</strong> automatically acquire the <strong id="EN-US_TOPIC_0000001233430195__b48890460433715">ROW SHARE</strong> lock on the target table and add the <strong id="EN-US_TOPIC_0000001233430195__b62630863533715">ACCESS SHARE</strong> lock to other referenced tables except <strong id="EN-US_TOPIC_0000001233430195__b47402782833715">FOR SHARE</strong> and <strong id="EN-US_TOPIC_0000001233430195__b101526597133715">FOR UPDATE</strong>.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__lbd4ab20ac345466ab4e64b07c662a884"><strong id="EN-US_TOPIC_0000001233430195__a5866672017174cbaac8a061f8c7a90af">ROW EXCLUSIVE</strong><p id="EN-US_TOPIC_0000001233430195__abe36bb977f2049ddac4f53426a3be092">Like <strong id="EN-US_TOPIC_0000001233430195__b30177226183935">ROW SHARE</strong>, <strong id="EN-US_TOPIC_0000001233430195__b3159584183935">ROW EXCLUSIVE</strong> allows concurrent read of a table and modification of data in the table. <strong id="EN-US_TOPIC_0000001233430195__b115553984133715">UPDATE</strong>, <strong id="EN-US_TOPIC_0000001233430195__b192185404933715">DELETE</strong>, and <strong id="EN-US_TOPIC_0000001233430195__b44150899533715">INSERT</strong> automatically acquire the <strong id="EN-US_TOPIC_0000001233430195__b46911376333715">ROW SHARE</strong> lock on the target table and add the <strong id="EN-US_TOPIC_0000001233430195__b158228875933715">ACCESS SHARE</strong> lock to other referenced tables. Generally, all commands that modify table data acquire the <strong id="EN-US_TOPIC_0000001233430195__b209360455833715">ROW EXCLUSIVE</strong> lock for tables.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__l6d4912192e4046d587267d2acab50c16"><strong id="EN-US_TOPIC_0000001233430195__a543a14fba3a94d4d9e9b6618e41ee585">SHARE UPDATE EXCLUSIVE</strong><p id="EN-US_TOPIC_0000001233430195__a3cb9e999803746629df501165b8c3913">This mode protects a table against concurrent schema changes and VACUUM runs.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__a36400251c8c34cc2841bac0adec0b741">Acquired by VACUUM (without FULL), ANALYZE, CREATE INDEX CONCURRENTLY, and some forms of ALTER TABLE.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__lda547306cbf84840a70b83c8539c810f"><strong id="EN-US_TOPIC_0000001233430195__a66cebbb0e7ec49e9aef91b8c426dde71">SHARE</strong><p id="EN-US_TOPIC_0000001233430195__a0230733fe7f34bbda7e4c7f34850c0be"><strong id="EN-US_TOPIC_0000001233430195__b30316646033715">SHARE</strong> allows concurrent queries of a table but does not allow modification of the table.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__a8dc36034496f47c0a6edaac7e60896b9">Acquired by CREATE INDEX (without CONCURRENTLY).</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__lcbabb9162e2249368dfaca9a75573295"><strong id="EN-US_TOPIC_0000001233430195__a8f655e6538d6470583a221f3f7dd3940">SHARE ROW EXCLUSIVE</strong><p id="EN-US_TOPIC_0000001233430195__a5cb9409d14264294b2ca73ab1049cab4"><strong id="EN-US_TOPIC_0000001233430195__b136623700533715">SHARE ROW EXCLUSIVE</strong> protects a table against concurrent data changes, and is self-exclusive so that only one session can hold it at a time.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__aa9efbc2538e641358513866d7555114d">No SQL statements automatically acquire this lock mode.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__l51ae488ae4194fcc9f245533cd3f7943"><strong id="EN-US_TOPIC_0000001233430195__a188ce7ee0eb74542b4ea707d9ce8bd78">EXCLUSIVE</strong><p id="EN-US_TOPIC_0000001233430195__a2ac2d0d256a140f2974f438dcb78511e"><strong id="EN-US_TOPIC_0000001233430195__b167862048533715">EXCLUSIVE</strong> allows concurrent queries of the target table but does not allow any other operations.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__abfbdc914843f4432a3945d57ed04a3ca">This mode allows only concurrent <strong id="EN-US_TOPIC_0000001233430195__b114325526733715">ACCESS SHARE</strong> locks; that is, only reads from the table can proceed in parallel with a transaction holding this lock mode.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__a72fcbc15ef2a4e29ba036e2fae7ea46a">No SQL statements automatically acquire this lock mode on user tables. However, it will be acquired on some system tables in case of some operations.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__lfb381ffaa64d47e99aa6b73fc2aebc3b"><strong id="EN-US_TOPIC_0000001233430195__a0f9995511f174af48ffc07ec235a3f5d">ACCESS EXCLUSIVE</strong><p id="EN-US_TOPIC_0000001233430195__a7d2cf6715b6c4ee0a68e5e7d9dc15ae6">This mode guarantees that the holder is the only transaction accessing the table in any way.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__a244d4889bb764045806314a8f8e935a4">Acquired by the <strong id="EN-US_TOPIC_0000001233430195__b96457050933715">ALTER TABLE</strong>, <strong id="EN-US_TOPIC_0000001233430195__b99855136833715">DROP TABLE</strong>, <strong id="EN-US_TOPIC_0000001233430195__b85526066533715">TRUNCATE</strong>, <strong id="EN-US_TOPIC_0000001233430195__b41567511633715">REINDEX</strong>, <strong id="EN-US_TOPIC_0000001233430195__b134407122833715">CLUSTER</strong>, and <strong id="EN-US_TOPIC_0000001233430195__b131681013633715">VACUUM FULL</strong> commands.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__ac96c7088bed84158a55d9d75e5a03d55">This is also the default lock mode for <strong id="EN-US_TOPIC_0000001233430195__b5268604133715">LOCK TABLE</strong> statements that do not specify a mode explicitly.</p>
|
|
</li><li id="EN-US_TOPIC_0000001233430195__lde394eca79494876b88a09d7d21231dd"><strong id="EN-US_TOPIC_0000001233430195__a9a490fd36e664143b619f418a66f1168">NOWAIT</strong><p id="EN-US_TOPIC_0000001233430195__a937309b6a169409d94b5ab941ee922c9">Specifies that <strong id="EN-US_TOPIC_0000001233430195__b45320027183935">LOCK TABLE</strong> should not wait for any conflicting locks to be released: if the specified lock(s) cannot be acquired immediately without waiting, the transaction is aborted.</p>
|
|
<p id="EN-US_TOPIC_0000001233430195__a5f7b2b1446d04c8089da5e6c8928931c">If <strong id="EN-US_TOPIC_0000001233430195__b52433432183935">NOWAIT</strong> is not specified, <strong id="EN-US_TOPIC_0000001233430195__b2138848183935">LOCK TABLE</strong> obtains a table-level lock, waiting if necessary for any conflicting locks to be released.</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001233430195__s4521fa51a8ca439a861325ad0633359a"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001233430195__p15611257194818">Obtain a <strong id="EN-US_TOPIC_0000001233430195__b144822537933715">SHARE</strong> lock on a primary key table when going to perform inserts into a foreign key table:</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430195__screen1725931554912"><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>
|
|
<span class="normal">11</span>
|
|
<span class="normal">12</span>
|
|
<span class="normal">13</span>
|
|
<span class="normal">14</span>
|
|
<span class="normal">15</span>
|
|
<span class="normal">16</span>
|
|
<span class="normal">17</span>
|
|
<span class="normal">18</span>
|
|
<span class="normal">19</span>
|
|
<span class="normal">20</span>
|
|
<span class="normal">21</span>
|
|
<span class="normal">22</span>
|
|
<span class="normal">23</span>
|
|
<span class="normal">24</span>
|
|
<span class="normal">25</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_address</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_address</span>
|
|
<span class="p">(</span>
|
|
<span class="w"> </span><span class="n">ca_address_sk</span><span class="w"> </span><span class="nb">INTEGER</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">ca_address_id</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="p">(</span><span class="mi">16</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">ca_street_number</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="p">,</span>
|
|
<span class="w"> </span><span class="n">ca_street_name</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="w"> </span><span class="nb">varying</span><span class="p">(</span><span class="mi">60</span><span class="p">)</span><span class="w"> </span><span class="p">,</span>
|
|
<span class="w"> </span><span class="n">ca_street_type</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span><span class="w"> </span><span class="p">,</span>
|
|
<span class="w"> </span><span class="n">ca_suite_number</span><span class="w"> </span><span class="nb">CHARACTER</span><span class="p">(</span><span class="mi">10</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="w"> </span><span class="p">(</span><span class="n">ca_address_sk</span><span class="p">)</span>
|
|
<span class="n">PARTITION</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="n">RANGE</span><span class="p">(</span><span class="n">ca_address_sk</span><span class="p">)</span>
|
|
<span class="p">(</span>
|
|
<span class="w"> </span><span class="n">PARTITION</span><span class="w"> </span><span class="n">P1</span><span class="w"> </span><span class="k">VALUES</span><span class="w"> </span><span class="k">LESS</span><span class="w"> </span><span class="k">THAN</span><span class="p">(</span><span class="mi">2450815</span><span class="p">),</span>
|
|
<span class="w"> </span><span class="n">PARTITION</span><span class="w"> </span><span class="n">P2</span><span class="w"> </span><span class="k">VALUES</span><span class="w"> </span><span class="k">LESS</span><span class="w"> </span><span class="k">THAN</span><span class="p">(</span><span class="mi">2451179</span><span class="p">),</span>
|
|
<span class="w"> </span><span class="n">PARTITION</span><span class="w"> </span><span class="n">P3</span><span class="w"> </span><span class="k">VALUES</span><span class="w"> </span><span class="k">LESS</span><span class="w"> </span><span class="k">THAN</span><span class="p">(</span><span class="mi">2451544</span><span class="p">),</span>
|
|
<span class="w"> </span><span class="n">PARTITION</span><span class="w"> </span><span class="n">P4</span><span class="w"> </span><span class="k">VALUES</span><span class="w"> </span><span class="k">LESS</span><span class="w"> </span><span class="k">THAN</span><span class="p">(</span><span class="k">MAXVALUE</span><span class="p">)</span>
|
|
<span class="p">);</span>
|
|
<span class="k">START</span><span class="w"> </span><span class="k">TRANSACTION</span><span class="p">;</span>
|
|
|
|
<span class="k">LOCK</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">customer_address</span><span class="w"> </span><span class="k">IN</span><span class="w"> </span><span class="k">SHARE</span><span class="w"> </span><span class="k">MODE</span><span class="p">;</span>
|
|
|
|
<span class="k">SELECT</span><span class="w"> </span><span class="n">ca_address_sk</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">customer_address</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">ca_address_sk</span><span class="o">=</span><span class="mi">5</span><span class="p">;</span>
|
|
|
|
<span class="k">COMMIT</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001233430195__p12611573488">Obtain a <strong id="EN-US_TOPIC_0000001233430195__b150666893433715">SHARE ROW EXCLUSIVE</strong> lock on a primary key table when going to perform a delete operation:</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233430195__screen1929603514491"><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>
|
|
<span class="normal">11</span>
|
|
<span class="normal">12</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="w"> </span><span class="k">AS</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">customer_address</span><span class="p">;</span>
|
|
|
|
<span class="k">START</span><span class="w"> </span><span class="k">TRANSACTION</span><span class="p">;</span>
|
|
|
|
<span class="k">LOCK</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">customer</span><span class="w"> </span><span class="k">IN</span><span class="w"> </span><span class="k">SHARE</span><span class="w"> </span><span class="k">ROW</span><span class="w"> </span><span class="k">EXCLUSIVE</span><span class="w"> </span><span class="k">MODE</span><span class="p">;</span>
|
|
|
|
<span class="k">DELETE</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">ca_address_sk</span><span class="w"> </span><span class="k">IN</span><span class="p">(</span><span class="k">SELECT</span><span class="w"> </span><span class="n">ca_address_sk</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">ca_address_sk</span><span class="w"> </span><span class="o"><</span><span class="w"> </span><span class="mi">6</span><span class="w"> </span><span class="p">);</span>
|
|
|
|
<span class="k">DELETE</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">ca_address_sk</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">7</span><span class="p">;</span>
|
|
|
|
<span class="k">COMMIT</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0227.html">DML Syntax</a></div>
|
|
</div>
|
|
</div>
|
|
|