Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This:</p> <pre><code>KEY `location_sh` (`dep_name`,`cat_name`,`loc_name`) </code></pre> <p>..defines an covering index called "location_sh". I specified "covering index", because the index declaration includes more than one column.</p> <pre><code>KEY `owner_sh` (`owner`) </code></pre> <p>...does not use more than one column, so it is just an <a href="http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html" rel="nofollow">index</a>. <code>KEY</code> is MySQL specific syntax for indexes -- though not covered by ANSI currently, every database implements indexes and uses similar terminology (after a fashion).</p> <p>The remaining CONSTRAINT declarations:</p> <pre><code>CONSTRAINT `location_sh` FOREIGN KEY (`dep_name`, `cat_name`, `loc_name`) REFERENCES `locations` (`dep_name`, `cat_name`, `loc_name`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `owner_sh` FOREIGN KEY (`owner`) REFERENCES `users` (`username`) ON DELETE SET NULL ON UPDATE CASCADE </code></pre> <p>...are <a href="http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html" rel="nofollow">foreign key constraints</a>. They are used to enforce referential integrity -- the columns defined can only have values that already exist in the table column(s) specified in the <code>REFERENCES</code> portion of the statement.</p> <p>Regarding the <code>ON DELETE ...</code> - the documentation says:</p> <blockquote> <p>The action InnoDB takes for any UPDATE or DELETE operation that attempts to update or delete a candidate key value in the parent table that has some matching rows in the child table is dependent on the referential action specified using ON UPDATE and ON DELETE subclauses of the FOREIGN KEY clause. When the user attempts to delete or update a row from a parent table, and there are one or more matching rows in the child table, InnoDB supports five options regarding the action to be taken. If ON DELETE or ON UPDATE are not specified, the default action is RESTRICT. </p> </blockquote> <h2>What changes should you make?</h2> <p>There's no context for us to say what is right or wrong, beyond syntax (which appears to be correct). It all depends on your data, and the business rules for that data.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload