<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="create-table-like">
      </a>
      15.1.20.3 CREATE TABLE ... LIKE Statement
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045185348800">
  </a>
  <a class="indexterm" name="idm46045185347760">
  </a>
  <p>
   Use
   <code class="literal">
    CREATE TABLE ... LIKE
   </code>
   to create an empty
        table based on the definition of another table, including any
        column attributes and indexes defined in the original table:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa29545273"><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-sql"><span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> <em class="replaceable">new_tbl</em> <span class="token operator">LIKE</span> <em class="replaceable">orig_tbl</em><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   The copy is created using the same version of the table storage
        format as the original table. The
   <a class="link" href="privileges-provided.html#priv_select">
    <code class="literal">
     SELECT
    </code>
   </a>
   privilege is required on
        the original table.
  </p>
  <p>
   <code class="literal">
    LIKE
   </code>
   works only for base tables, not for
        views.
  </p>
  <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Important
   </div>
   <p>
    You cannot execute
    <code class="literal">
     CREATE TABLE
    </code>
    or
    <code class="literal">
     CREATE TABLE ... LIKE
    </code>
    while a
    <a class="link" href="lock-tables.html" title="15.3.6 LOCK TABLES and UNLOCK TABLES Statements">
     <code class="literal">
      LOCK TABLES
     </code>
    </a>
    statement is in
          effect.
   </p>
   <p>
    <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
     <code class="literal">
      CREATE TABLE ...
          LIKE
     </code>
    </a>
    makes the same checks as
    <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
     <code class="literal">
      CREATE TABLE
     </code>
    </a>
    . This means that
          if the current SQL mode is different from the mode in effect
          when the original table was created, the table definition
          might be considered invalid for the new mode and cause the
          statement to fail.
   </p>
  </div>
  <p>
   For
   <code class="literal">
    CREATE TABLE ... LIKE
   </code>
   , the destination
        table preserves generated column information from the original
        table.
  </p>
  <p>
   For
   <code class="literal">
    CREATE TABLE ... LIKE
   </code>
   , the destination
        table preserves expression default values from the original
        table.
  </p>
  <p>
   For
   <code class="literal">
    CREATE TABLE ... LIKE
   </code>
   , the destination
        table preserves
   <code class="literal">
    CHECK
   </code>
   constraints from the
        original table, except that all the constraint names are
        generated.
  </p>
  <p>
   <code class="literal">
    CREATE TABLE ... LIKE
   </code>
   does not preserve any
   <code class="literal">
    DATA DIRECTORY
   </code>
   or
   <code class="literal">
    INDEX
        DIRECTORY
   </code>
   table options that were specified for the
        original table, or any foreign key definitions.
  </p>
  <p>
   If the original table is a
   <code class="literal">
    TEMPORARY
   </code>
   table,
   <code class="literal">
    CREATE TABLE ... LIKE
   </code>
   does not preserve
   <code class="literal">
    TEMPORARY
   </code>
   . To create a
   <code class="literal">
    TEMPORARY
   </code>
   destination table, use
   <code class="literal">
    CREATE TEMPORARY TABLE ... LIKE
   </code>
   .
  </p>
  <p>
   <a class="link" href="create-table-like.html" title="15.1.20.3 CREATE TABLE ... LIKE Statement">
    <code class="literal">
     CREATE TABLE
        ... LIKE
    </code>
   </a>
   operations apply all
   <code class="literal">
    ENGINE_ATTRIBUTE
   </code>
   and
   <code class="literal">
    SECONDARY_ENGINE_ATTRIBUTE
   </code>
   values to the new
        table.
  </p>
 </div>
 <br/>
</div>
