Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you're confusing the difference between a <em>foreign key constraint</em> and a <em>check constraint</em>.</p> <p>A <em>foreign key constraint</em> is there to enforce referential integrity and a <em>check constraint</em> constrains a column to containing only valid data. In your case this may seem like a minor difference but if we abstract it slightly I hope to make it clearer.</p> <p>If we consider a table <code>users</code> with the columns <code>user_id, user_name, address_id, join_date, active, last_active_month</code>; I recognise that this is not necessarily the best way of doing things but it'll serve for the point I'm trying to make.</p> <p>In this case it's patently ridiculous to have <code>address_id</code> as a constraint. This column could have any number of values. However, <code>active</code>, assuming we want a boolean <code>y/n</code> can only have two possible values and <code>last_active_month</code> can only have 12 possible values. In both these cases it's completely ridiculous to have a foreign key. There are only a certain number of values and by the definition of the data you are including these values <strong>cannot</strong> change.</p> <p>In your case, while you could go for a <em>check constraint</em>, unless you can be <strong>absolutely certain</strong> that the number of <code>actions</code> will never change a <em>foreign key</em> is the correct way to go.</p> <hr> <p>On a slightly separate matter, and as @pst mentioned, I see you've been eaten by the surrogate key monster. While this <em>can</em> result in performance improvements, in a table of the size you're envisaging ( 3 values, <code>insert / update / delete</code> ) or even a larger one all it serves to do is obscure what you're trying to achieve. </p> <p>It's not easy to look at</p> <pre><code>ID Action System 1 1 1 2 2 1 </code></pre> <p>and see what's going on, but:</p> <pre><code>ID Action System 1 insert 1 2 update 1 </code></pre> <p>is far easier to read; you may also want to consider doing the same for the <code>system</code> column - I probably would, though the number of possible values jumps slightly in this. Just my personal thoughts on the matter...</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.
    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