Question

I suspect that this is going to sound like a stupid question, but, having just migrated a bunch of identikit lookup tables of the form (id, value, is_default) into a single large general lookup table at my boss's behest of the form (id, type, value, is_default), is there a nice way to set up referential integrity from the tables that now refer to this one?

One suggestion is to set up a view for each 'type' in the new table, which of course means that I'll have spent the better part of two weeks chasing my tail to only get back to pretty much where I started.

Am I stuck with that, or is there something like "FOREIGN KEY (x_type_id) REFERENCES general_values (id) WHERE type="x" ? Or something cleverer still.

Thanks!

Was it helpful?

Solution

is there something like "FOREIGN KEY (x_type_id) REFERENCES general_values (id) WHERE type="x" ?

No there is nothing like conditional referential integrity in MySQL.

We cannot have conditional referential integrity check, though you can check if pro grammatically.

Edit:

This post discuss on the same line what you want to achieve.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top