Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://en.wikipedia.org/wiki/Foreign_key" rel="nofollow noreferrer">Foreign keys</a> will guarantee that a row in a table <code>order_details</code> with a field <code>order_id</code> referencing an <code>orders</code> table will never have an <code>order_id</code> value that doesn't exist in the <code>orders</code> table. </p> <p>Foreign keys aren't required to have a working relational database, but they are definitely essential to avoid broken relationships and orphan rows (ie. <a href="http://en.wikipedia.org/wiki/Referential_integrity" rel="nofollow noreferrer">referential integrity</a>). The ability to enforce referential integrity at the database level is required for the <em>C</em> in <a href="http://en.wikipedia.org/wiki/ACID" rel="nofollow noreferrer">ACID</a> to stand.</p> <p>As for your concerns regarding performance, in general the performance hit, if any, will be negligible. I suggest putting in all your foreign key constraints, and only experiment without them if you have real performance issues that you cannot solve otherwise.</p> <p>In addition, as a side-note, while not directly related to MySQL, this is quote from <a href="http://msdn.microsoft.com/en-us/library/ms998577.aspx" rel="nofollow noreferrer">Microsoft Patterns and Practices: Chapter 14 Improving SQL Server Performance</a>:</p> <blockquote> <p>When primary and foreign keys are defined as constraints in the database schema, the server can use that information to create optimal execution plans.</p> </blockquote>
 

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