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 other systems data is updated. There will be a sync_action table to identify which system the central repo needs to sync with and the type of sync required. There are set of defined actions that is very unlikely to change. A slimmed down system is below.
As I see it I can approach this in two ways:
Option 1) Have an Action
table that has the 3 actions available. Have a sync_action
table which uses a foreign key to reference the actions required.
Table: System
ID Description
1 Slave System 1
2 Slave System 2
Table: Action
ID Description
1 Insert
2 Update
3 Delete
Table: Sync_action
ID Action System
1 1 1
2 2 1
Option 2) Instead of a foreign key use a check constraint on the sync_action.action
column so only the actions Insert/Update/Delete
can be inserted.
Table: Sync_action
ID Action System
1 Insert 1
2 Update 1
I would like to know what factors go into determining which is a better approach when deciding between integrity constraints, foreign key vs check constraint. There have been similar threads but I didn't find them definitive enough. This may be because its up to interpretation but any thoughts would be appreciated.
Cheers
{ }
) on the editor toolbar to nicely format and syntax highlight it! – Occultpst
- what if you need to add a fourth, fifth action?? If you have a separateAction
table, it's as simple as adding a row. If you have check constraints, you need to go drop and recreate those - that's more work, and more hassle. I don't see any good arguments against having a separateAction
table and enforcing referential integrity using a FK constraint - databases are good at that! (that's their core business!) – Occult