<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="information-schema-key-column-usage-table">
      </a>
      28.3.16 The INFORMATION_SCHEMA KEY_COLUMN_USAGE Table
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045079588928">
  </a>
  <p>
   The
   <a class="link" href="information-schema-key-column-usage-table.html" title="28.3.16 The INFORMATION_SCHEMA KEY_COLUMN_USAGE Table">
    <code class="literal">
     KEY_COLUMN_USAGE
    </code>
   </a>
   table describes
      which key columns have constraints. This table provides no
      information about functional key parts because they are
      expressions and the table provides information only about columns.
  </p>
  <p>
   The
   <a class="link" href="information-schema-key-column-usage-table.html" title="28.3.16 The INFORMATION_SCHEMA KEY_COLUMN_USAGE Table">
    <code class="literal">
     KEY_COLUMN_USAGE
    </code>
   </a>
   table has these
      columns:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <code class="literal">
       CONSTRAINT_CATALOG
      </code>
     </p>
     <p>
      The name of the catalog to which the constraint belongs. This
          value is always
      <code class="literal">
       def
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       CONSTRAINT_SCHEMA
      </code>
     </p>
     <p>
      The name of the schema (database) to which the constraint
          belongs.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       CONSTRAINT_NAME
      </code>
     </p>
     <p>
      The name of the constraint.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       TABLE_CATALOG
      </code>
     </p>
     <p>
      The name of the catalog to which the table belongs. This value
          is always
      <code class="literal">
       def
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       TABLE_SCHEMA
      </code>
     </p>
     <p>
      The name of the schema (database) to which the table belongs.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       TABLE_NAME
      </code>
     </p>
     <p>
      The name of the table that has the constraint.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       COLUMN_NAME
      </code>
     </p>
     <p>
      The name of the column that has the constraint.
     </p>
     <p>
      If the constraint is a foreign key, then this is the column of
          the foreign key, not the column that the foreign key
          references.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       ORDINAL_POSITION
      </code>
     </p>
     <p>
      The column's position within the constraint, not the column's
          position within the table. Column positions are numbered
          beginning with 1.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       POSITION_IN_UNIQUE_CONSTRAINT
      </code>
     </p>
     <p>
      <code class="literal">
       NULL
      </code>
      for unique and primary-key
          constraints. For foreign-key constraints, this column is the
          ordinal position in key of the table that is being referenced.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       REFERENCED_TABLE_SCHEMA
      </code>
     </p>
     <p>
      The name of the schema referenced by the constraint.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       REFERENCED_TABLE_NAME
      </code>
     </p>
     <p>
      The name of the table referenced by the constraint.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       REFERENCED_COLUMN_NAME
      </code>
     </p>
     <p>
      The name of the column referenced by the constraint.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Suppose that there are two tables name
   <code class="literal">
    t1
   </code>
   and
   <code class="literal">
    t3
   </code>
   that have the following definitions:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa60873672"><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>
    s1 <span class="token datatype">INT</span><span class="token punctuation">,</span>
    s2 <span class="token datatype">INT</span><span class="token punctuation">,</span>
    s3 <span class="token datatype">INT</span><span class="token punctuation">,</span>
    <span class="token keyword">PRIMARY</span> <span class="token keyword">KEY</span><span class="token punctuation">(</span>s3<span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span>InnoDB<span class="token punctuation">;</span>

<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> t3
<span class="token punctuation">(</span>
    s1 <span class="token datatype">INT</span><span class="token punctuation">,</span>
    s2 <span class="token datatype">INT</span><span class="token punctuation">,</span>
    s3 <span class="token datatype">INT</span><span class="token punctuation">,</span>
    <span class="token keyword">KEY</span><span class="token punctuation">(</span>s1<span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token keyword">CONSTRAINT</span> CO <span class="token keyword">FOREIGN</span> <span class="token keyword">KEY</span> <span class="token punctuation">(</span>s2<span class="token punctuation">)</span> <span class="token keyword">REFERENCES</span> t1<span class="token punctuation">(</span>s3<span class="token punctuation">)</span>
<span class="token punctuation">)</span> <span class="token keyword">ENGINE</span><span class="token operator">=</span>InnoDB<span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   For those two tables, the
   <a class="link" href="information-schema-key-column-usage-table.html" title="28.3.16 The INFORMATION_SCHEMA KEY_COLUMN_USAGE Table">
    <code class="literal">
     KEY_COLUMN_USAGE
    </code>
   </a>
   table has two rows:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      One row with
      <code class="literal">
       CONSTRAINT_NAME
      </code>
      =
      <code class="literal">
       'PRIMARY'
      </code>
      ,
      <code class="literal">
       TABLE_NAME
      </code>
      =
      <code class="literal">
       't1'
      </code>
      ,
      <code class="literal">
       COLUMN_NAME
      </code>
      =
      <code class="literal">
       's3'
      </code>
      ,
      <code class="literal">
       ORDINAL_POSITION
      </code>
      =
      <code class="literal">
       1
      </code>
      ,
      <code class="literal">
       POSITION_IN_UNIQUE_CONSTRAINT
      </code>
      =
      <code class="literal">
       NULL
      </code>
      .
     </p>
     <p>
      For
      <code class="literal">
       NDB
      </code>
      : This value is always
      <code class="literal">
       NULL
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      One row with
      <code class="literal">
       CONSTRAINT_NAME
      </code>
      =
      <code class="literal">
       'CO'
      </code>
      ,
      <code class="literal">
       TABLE_NAME
      </code>
      =
      <code class="literal">
       't3'
      </code>
      ,
      <code class="literal">
       COLUMN_NAME
      </code>
      =
      <code class="literal">
       's2'
      </code>
      ,
      <code class="literal">
       ORDINAL_POSITION
      </code>
      =
      <code class="literal">
       1
      </code>
      ,
      <code class="literal">
       POSITION_IN_UNIQUE_CONSTRAINT
      </code>
      =
      <code class="literal">
       1
      </code>
      .
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
