I am building a system that is a central repository for storing data from a number of other systems. A sync process is required to update the central repository when the oth
I think you're confusing the difference between a foreign key constraint and a check constraint.
A foreign key constraint is there to enforce referential integrity and a check constraint 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.
If we consider a table users
with the columns user_id, user_name, address_id, join_date, active, last_active_month
; 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.
In this case it's patently ridiculous to have address_id
as a constraint. This column could have any number of values. However, active
, assuming we want a boolean y/n
can only have two possible values and last_active_month
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 cannot change.
In your case, while you could go for a check constraint, unless you can be absolutely certain that the number of actions
will never change a foreign key is the correct way to go.
On a slightly separate matter, and as @pst mentioned, I see you've been eaten by the surrogate key monster. While this can result in performance improvements, in a table of the size you're envisaging ( 3 values, insert / update / delete
) or even a larger one all it serves to do is obscure what you're trying to achieve.
It's not easy to look at
ID Action System
1 1 1
2 2 1
and see what's going on, but:
ID Action System
1 insert 1
2 update 1
is far easier to read; you may also want to consider doing the same for the system
column - I probably would, though the number of possible values jumps slightly in this. Just my personal thoughts on the matter...