<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="mysql-shell-tutorial-python-table-delete">
      </a>
      22.4.4.4 Delete Tables
     </h4>
    </div>
   </div>
  </div>
  <p>
   You can use the
   <code class="literal">
    delete()
   </code>
   method to remove
        some or all records from a table in a database. The X DevAPI
        provides additional methods to use with the
   <code class="literal">
    delete()
   </code>
   method to filter and order the
        records to be deleted.
  </p>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="mysql-shell-tutorial-python-delete-records-using-conditions">
       </a>
       Delete Records Using Conditions
      </h5>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045126769360">
   </a>
   <p>
    The example that follows passes search conditions to the
    <code class="literal">
     delete()
    </code>
    method. All records matching the
          condition are deleted from the
    <code class="literal">
     city
    </code>
    table.
          In this example, one record matches the condition.
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa43379249"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-mysqlsh"><span class="token prompt">mysql-py&gt;</span> db<span class="token punctuation">.</span>city<span class="token punctuation">.</span><span class="token keyword">delete</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">where</span><span class="token punctuation">(</span><span class="token string">"Name = 'Olympia'"</span><span class="token punctuation">)</span></code></pre>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="mysql-shell-tutorial-python-delete-first-record">
       </a>
       Delete the First Record
      </h5>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045126762768">
   </a>
   <p>
    To delete the first record in the city table, use the
    <code class="literal">
     limit()
    </code>
    method with a value of 1.
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa97200748"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-mysqlsh"><span class="token prompt">mysql-py&gt;</span> db<span class="token punctuation">.</span>city<span class="token punctuation">.</span><span class="token keyword">delete</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">limit</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span></code></pre>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="mysql-shell-tutorial-python-delete-all-records">
       </a>
       Delete All Records in a Table
      </h5>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045126757088">
   </a>
   <p>
    You can delete all records in a table. To do so, use the
    <code class="literal">
     delete()
    </code>
    method without specifying a search
          condition.
   </p>
   <div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Caution
    </div>
    <p>
     Use care when you delete records without specifying a search
            condition; doing so deletes all records from the table.
    </p>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="mysql-shell-tutorial-python-drop-table">
       </a>
       Drop a Table
      </h5>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045126752240">
   </a>
   <p>
    The
    <code class="literal">
     drop_collection()
    </code>
    method is also used
          in MySQL Shell to drop a relational table from a database.
          For example, to drop the
    <code class="literal">
     citytest
    </code>
    table
          from the
    <code class="literal">
     world_x
    </code>
    database, issue:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-mysqlsh"><div class="docs-select-all right" id="sa80011897"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-mysqlsh"><span class="token prompt">mysql-py&gt;</span> db<span class="token punctuation">.</span><span class="token function">drop_collection</span><span class="token punctuation">(</span><span class="token string">"citytest"</span><span class="token punctuation">)</span></code></pre>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h5 class="title">
       <a name="idm46045126746272">
       </a>
       Related Information
      </h5>
     </div>
    </div>
   </div>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       See
       <a class="ulink" href="/doc/x-devapi-userguide/en/crud-ebnf-table-crud-functions.html#crud-ebnf-tabledeletefunction" target="_top">
        TableDeleteFunction
       </a>
       for
              the full syntax definition.
      </p>
     </li>
     <li class="listitem">
      <p>
       See
       <a class="xref" href="mysql-shell-tutorial-python-download.html" title="22.4.2 Download and Import world_x Database">
        Section 22.4.2, “Download and Import world_x Database”
       </a>
       for instructions to recreate the
       <code class="literal">
        world_x
       </code>
       database.
      </p>
     </li>
    </ul>
   </div>
  </div>
 </div>
 <br/>
</div>
