<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="constraint-enum">
      </a>
      1.7.3.3 ENUM and SET Constraints
     </h4>
    </div>
   </div>
  </div>
  <p>
   <a class="link" href="enum.html" title="13.3.5 The ENUM Type">
    <code class="literal">
     ENUM
    </code>
   </a>
   and
   <a class="link" href="set.html" title="13.3.6 The SET Type">
    <code class="literal">
     SET
    </code>
   </a>
   columns provide an
          efficient way to define columns that can contain only a given
          set of values. See
   <a class="xref" href="enum.html" title="13.3.5 The ENUM Type">
    Section 13.3.5, “The ENUM Type”
   </a>
   , and
   <a class="xref" href="set.html" title="13.3.6 The SET Type">
    Section 13.3.6, “The SET Type”
   </a>
   .
  </p>
  <p>
   Unless strict mode is disabled (not recommended, but see
   <a class="xref" href="sql-mode.html" title="7.1.11 Server SQL Modes">
    Section 7.1.11, “Server SQL Modes”
   </a>
   ), the definition of a
   <a class="link" href="enum.html" title="13.3.5 The ENUM Type">
    <code class="literal">
     ENUM
    </code>
   </a>
   or
   <a class="link" href="set.html" title="13.3.6 The SET Type">
    <code class="literal">
     SET
    </code>
   </a>
   column acts as a constraint
          on values entered into the column. An error occurs for values
          that do not satisfy these conditions:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      An
      <a class="link" href="enum.html" title="13.3.5 The ENUM Type">
       <code class="literal">
        ENUM
       </code>
      </a>
      value must be one
              of those listed in the column definition, or the internal
              numeric equivalent thereof. The value cannot be the error
              value (that is, 0 or the empty string). For a column
              defined as
      <a class="link" href="enum.html" title="13.3.5 The ENUM Type">
       <code class="literal">
        ENUM('a','b','c')
       </code>
      </a>
      , values
              such as
      <code class="literal">
       ''
      </code>
      ,
      <code class="literal">
       'd'
      </code>
      , or
      <code class="literal">
       'ax'
      </code>
      are invalid and are rejected.
     </p>
    </li>
    <li class="listitem">
     <p>
      A
      <a class="link" href="set.html" title="13.3.6 The SET Type">
       <code class="literal">
        SET
       </code>
      </a>
      value must be the
              empty string or a value consisting only of the values
              listed in the column definition separated by commas. For a
              column defined as
      <a class="link" href="set.html" title="13.3.6 The SET Type">
       <code class="literal">
        SET('a','b','c')
       </code>
      </a>
      , values
              such as
      <code class="literal">
       'd'
      </code>
      or
      <code class="literal">
       'a,b,c,d'
      </code>
      are invalid and are rejected.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Errors for invalid values can be suppressed in strict mode if
          you use
   <a class="link" href="insert.html" title="15.2.7 INSERT Statement">
    <code class="literal">
     INSERT
          IGNORE
    </code>
   </a>
   or
   <code class="literal">
    UPDATE IGNORE
   </code>
   . In this
          case, a warning is generated rather than an error. For
   <a class="link" href="enum.html" title="13.3.5 The ENUM Type">
    <code class="literal">
     ENUM
    </code>
   </a>
   , the value is inserted as
          the error member (
   <code class="literal">
    0
   </code>
   ). For
   <a class="link" href="set.html" title="13.3.6 The SET Type">
    <code class="literal">
     SET
    </code>
   </a>
   , the value is inserted as
          given except that any invalid substrings are deleted. For
          example,
   <code class="literal">
    'a,x,b,y'
   </code>
   results in a value of
   <code class="literal">
    'a,b'
   </code>
   .
  </p>
 </div>
 <br/>
</div>
