Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your pizza can have exactly three topping types: </p> <ul> <li>one type of cheese</li> <li>one type of meat</li> <li>one type of vegetable</li> </ul> <p>So we order two pizzas and choose the following toppings:</p> <pre><code>Pizza Topping Topping Type -------- ---------- ------------- 1 mozzarella cheese 1 pepperoni meat 1 olives vegetable 2 mozzarella meat 2 sausage cheese 2 peppers vegetable </code></pre> <p>Wait a second, mozzarella can't be both a cheese and a meat! And sausage isn't a cheese!</p> <p>We need to prevent these sorts of mistakes, to make mozzarella <em>always</em> be cheese. We should use a separate table for this, so we write down that fact in only one place.</p> <pre><code>Pizza Topping -------- ---------- 1 mozzarella 1 pepperoni 1 olives 2 mozzarella 2 sausage 2 peppers Topping Topping Type ---------- ------------- mozzarella cheese pepperoni meat olives vegetable sausage meat peppers vegetable </code></pre> <hr> <p>That was the explanation that an 8 year-old might understand. Here is the more technical version.</p> <p><em>BCNF acts differently from 3NF only when there are multiple overlapping candidate keys.</em> </p> <p>The reason is that the functional dependency <code>X -&gt; Y</code> is of course true if <code>Y</code> is a subset of <code>X</code>. So in any table that has only one candidate key and is in 3NF, it is already in BCNF because there is no column (either key or non-key) that is functionally dependent on anything besides that key.</p> <p>Because each pizza must have exactly one of each topping type, we know that (Pizza, Topping Type) is a candidate key. We also know intuitively that a given topping cannot belong to different types simultaneously. So (Pizza, Topping) must be unique and therefore is also a candidate key. So we have two overlapping candidate keys.</p> <p>I showed an anomaly where we marked mozarella as the wrong topping type. We know this is wrong, but the rule that makes it wrong is a dependency <code>Topping -&gt; Topping Type</code> which is not a valid dependency for BCNF for this table. It's a dependency on something other than a whole candidate key.</p> <p>So to solve this, we take Topping Type out of the Pizzas table and make it a non-key attribute in a Toppings table.</p>
    singulars
    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. 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.
    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