<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="charset-table">
      </a>
      12.3.4 Table Character Set and Collation
     </h3>
    </div>
   </div>
  </div>
  <p>
   Every table has a table character set and a table collation. The
   <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
    <code class="literal">
     CREATE TABLE
    </code>
   </a>
   and
   <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
    <code class="literal">
     ALTER TABLE
    </code>
   </a>
   statements have
        optional clauses for specifying the table character set and
        collation:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa79487689"><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">tbl_name</em> <span class="token punctuation">(</span><em class="replaceable">column_list</em><span class="token punctuation">)</span>
    <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token keyword">DEFAULT</span><span class="token punctuation">]</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <em class="replaceable">charset_name</em><span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token keyword">COLLATE</span> <em class="replaceable">collation_name</em><span class="token punctuation">]</span><span class="token punctuation">]</span>

<span class="token keyword">ALTER</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em>
    <span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token keyword">DEFAULT</span><span class="token punctuation">]</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <em class="replaceable">charset_name</em><span class="token punctuation">]</span>
    <span class="token punctuation">[</span><span class="token keyword">COLLATE</span> <em class="replaceable">collation_name</em><span class="token punctuation">]</span></code></pre>
  </div>
  <p>
   Example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa14420203"><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> t1 <span class="token punctuation">(</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token punctuation">)</span>
<span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> latin1 <span class="token keyword">COLLATE</span> latin1_danish_ci<span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   MySQL chooses the table character set and collation in the
        following manner:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      If both
      <code class="literal">
       CHARACTER SET
       <em class="replaceable">
        <code>
         charset_name
        </code>
       </em>
      </code>
      and
      <code class="literal">
       COLLATE
       <em class="replaceable">
        <code>
         collation_name
        </code>
       </em>
      </code>
      are
            specified, character set
      <em class="replaceable">
       <code>
        charset_name
       </code>
      </em>
      and collation
      <em class="replaceable">
       <code>
        collation_name
       </code>
      </em>
      are used.
     </p>
    </li>
    <li class="listitem">
     <p>
      If
      <code class="literal">
       CHARACTER SET
       <em class="replaceable">
        <code>
         charset_name
        </code>
       </em>
      </code>
      is
            specified without
      <code class="literal">
       COLLATE
      </code>
      , character set
      <em class="replaceable">
       <code>
        charset_name
       </code>
      </em>
      and its default
            collation are used. To see the default collation for each
            character set, use the
      <a class="link" href="show-character-set.html" title="15.7.7.4 SHOW CHARACTER SET Statement">
       <code class="literal">
        SHOW CHARACTER
            SET
       </code>
      </a>
      statement or query the
      <code class="literal">
       INFORMATION_SCHEMA
      </code>
      <a class="link" href="information-schema-character-sets-table.html" title="28.3.4 The INFORMATION_SCHEMA CHARACTER_SETS Table">
       <code class="literal">
        CHARACTER_SETS
       </code>
      </a>
      table.
     </p>
    </li>
    <li class="listitem">
     <p>
      If
      <code class="literal">
       COLLATE
       <em class="replaceable">
        <code>
         collation_name
        </code>
       </em>
      </code>
      is
            specified without
      <code class="literal">
       CHARACTER SET
      </code>
      , the
            character set associated with
      <em class="replaceable">
       <code>
        collation_name
       </code>
      </em>
      and collation
      <em class="replaceable">
       <code>
        collation_name
       </code>
      </em>
      are used.
     </p>
    </li>
    <li class="listitem">
     <p>
      Otherwise (neither
      <code class="literal">
       CHARACTER SET
      </code>
      nor
      <code class="literal">
       COLLATE
      </code>
      is specified), the database
            character set and collation are used.
     </p>
    </li>
   </ul>
  </div>
  <p>
   The table character set and collation are used as default values
        for column definitions if the column character set and collation
        are not specified in individual column definitions. The table
        character set and collation are MySQL extensions; there are no
        such things in standard SQL.
  </p>
 </div>
 <br/>
</div>
