<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="mysql-shell-tutorial-javascript-relational-tables">
      </a>
      22.3.4 Relational Tables
     </h3>
    </div>
   </div>
  </div>
  <div class="toc">
   <dl class="toc">
    <dt>
     <span class="section">
      <a href="mysql-shell-tutorial-javascript-table-insert.html">
       22.3.4.1 Insert Records into Tables
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="mysql-shell-tutorial-javascript-table-select.html">
       22.3.4.2 Select Tables
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="mysql-shell-tutorial-javascript-table-update.html">
       22.3.4.3 Update Tables
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="mysql-shell-tutorial-javascript-table-delete.html">
       22.3.4.4 Delete Tables
      </a>
     </span>
    </dt>
   </dl>
  </div>
  <a class="indexterm" name="idm46045127653888">
  </a>
  <p>
   You can also use X DevAPI to work with relational tables. In
      MySQL, each relational table is associated with a particular
      storage engine. The examples in this section use
   <a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
    <code class="literal">
     InnoDB
    </code>
   </a>
   tables in the
   <code class="literal">
    world_x
   </code>
   schema.
  </p>
  <h4>
   <a name="idm46045127649840">
   </a>
   Confirm the Schema
  </h4>
  <p>
   To show the schema that is assigned to the
   <code class="literal">
    db
   </code>
   global variable, issue
   <code class="literal">
    db
   </code>
   .
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa7465531"><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-js&gt;</span> db
<span class="token operator">&lt;</span>Schema<span class="token punctuation">:</span>world_x<span class="token operator">&gt;</span></code></pre>
  </div>
  <p>
   If the returned value is not
   <code class="literal">
    Schema:world_x
   </code>
   ,
      set the
   <code class="literal">
    db
   </code>
   variable as follows:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa3353430"><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-js&gt;</span> \use world_x
Schema <span class="token template-string"><span class="token string">`world_x`</span></span> accessible through db<span class="token punctuation">.</span></code></pre>
  </div>
  <h4>
   <a name="idm46045127642144">
   </a>
   Show All Tables
  </h4>
  <p>
   To display all relational tables in the
   <code class="literal">
    world_x
   </code>
   schema, use the
   <code class="literal">
    getTables()
   </code>
   method on the
   <code class="literal">
    db
   </code>
   object.
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-mysqlsh"><div class="docs-select-all right" id="sa11796249"><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-js&gt;</span> db<span class="token punctuation">.</span><span class="token function">getTables</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token inlinejson"><span class="token punctuation">{</span>
    <span class="token property">"city"</span><span class="token operator">:</span> &lt;Table<span class="token operator">:</span>city&gt;<span class="token punctuation">,</span>
    <span class="token property">"country"</span><span class="token operator">:</span> &lt;Table<span class="token operator">:</span>country&gt;<span class="token punctuation">,</span>
    <span class="token property">"countrylanguage"</span><span class="token operator">:</span> &lt;Table<span class="token operator">:</span>countrylanguage&gt;
<span class="token punctuation">}</span></span></code></pre>
  </div>
  <h4>
   <a name="idm46045127636976">
   </a>
   Basic Table Operations
  </h4>
  <p>
   Basic operations scoped by tables include:
  </p>
  <div class="informaltable">
   <table summary="CRUD operations to use interactively on tables within MySQL Shell">
    <colgroup>
     <col style="width: 32%"/>
     <col style="width: 68%"/>
    </colgroup>
    <thead>
     <tr>
      <th>
       Operation form
      </th>
      <th>
       Description
      </th>
     </tr>
    </thead>
    <tbody>
     <tr>
      <td>
       <code class="literal">
        db.
        <em class="replaceable">
         <code>
          name
         </code>
        </em>
        .insert()
       </code>
      </td>
      <td>
       The
       <a class="link" href="mysql-shell-tutorial-javascript-table-insert.html" title="22.3.4.1 Insert Records into Tables">
        insert()
       </a>
       method inserts one or more records into the named table.
      </td>
     </tr>
     <tr>
      <td>
       <code class="literal">
        db.
        <em class="replaceable">
         <code>
          name
         </code>
        </em>
        .select()
       </code>
      </td>
      <td>
       The
       <a class="link" href="mysql-shell-tutorial-javascript-table-select.html" title="22.3.4.2 Select Tables">
        select()
       </a>
       method returns some or all records in the named table.
      </td>
     </tr>
     <tr>
      <td>
       <code class="literal">
        db.
        <em class="replaceable">
         <code>
          name
         </code>
        </em>
        .update()
       </code>
      </td>
      <td>
       The
       <a class="link" href="mysql-shell-tutorial-javascript-table-update.html" title="22.3.4.3 Update Tables">
        update()
       </a>
       method updates records in the named table.
      </td>
     </tr>
     <tr>
      <td>
       <code class="literal">
        db.
        <em class="replaceable">
         <code>
          name
         </code>
        </em>
        .delete()
       </code>
      </td>
      <td>
       The
       <a class="link" href="mysql-shell-tutorial-javascript-table-delete.html" title="22.3.4.4 Delete Tables">
        delete()
       </a>
       method deletes one or more records from the named table.
      </td>
     </tr>
    </tbody>
   </table>
  </div>
  <h4>
   <a name="idm46045127614160">
   </a>
   Related Information
  </h4>
  <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/devapi-users-working-with-relational-tables.html" target="_top">
       Working with Relational Tables
      </a>
      for more information.
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="ulink" href="/doc/x-devapi-userguide/en/mysql-x-crud-ebnf-definitions.html" target="_top">
       CRUD EBNF Definitions
      </a>
      provides a
          complete list of operations.
     </p>
    </li>
    <li class="listitem">
     <p>
      See
      <a class="xref" href="mysql-shell-tutorial-javascript-download.html" title="22.3.2 Download and Import world_x Database">
       Section 22.3.2, “Download and Import world_x Database”
      </a>
      for instructions on setting up the
      <code class="literal">
       world_x
      </code>
      schema sample.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
