I would like to pull 4 columns into one so that the unique concatenated value can be more easily distributed throughout the database as foreign key restraints. The 4 column info is important identifying info that I would like to have readily accessible throughout the child tables that are connected to it.
The reason I need the data to come in as 4 chunks, is each part is validated by an enum() value or integer length. None are unique on their own, but combined, they are..
Ideally I would still be able access this data separately (e.g. sort on B)
The options I see are this:
- Create composite primary keys, from A, B, C, D and then include A, B, C, D as columns in every table that references it (<-- seems to be the way, but feels clunky -- in most child tables the data will only be utilized as ABCD.)
- Create a series of triggers that take A, B, C, D and concatenate them into a new column ABCD, and make THAT column the PK (and make sure to keep the updated if one of the component parts changes -- which they shouldn't, but...) Then I can reference ABCD in every child table.
- Utilize a BEFORE UPDATE Trigger that validates the data before placing it into the ABCD PK column then also places it in the A, B, C, D columns (this may be a derivation on 2, or the same)
The complicating factor is that ideally the UI needs to request A, B, C, and D separately, but I can't guarantee the UI program will be able to validate the data for me.
Edit: The goal is to make the database as simple and understandable as possible for the next admin. So tricky Triggers are less ideal than a native solution.
I don't suppose you can define a column that is a concat of other columns?