I can not find this any where (I am probably not asking the right questions). Would someone please point me in the right direction.
I am using a 2 column composite primary key in MySQL.
I would like to display that value as a default value in a 3rd column in the same table and in another table.
Col_1 value = ABC,
Col_2 value = 123,
PK = ABC123,
Col_3 default value = ABC123
Would anyone be able to explain how to do this?
I would prefer not to do this with a trigger or an insert statement if possible.
Thanks,
Ted
There aren’t many situations where you really need the value to actually be in the column. You can get the same effect many times by creating the value in the select statement you use to fetch the data — or in the php, ruby or whatever code you use to display the data.
For example:
This will resolve the issue for you while avoiding triggers and other fancy sql tricks.
I think this is a better approach as well in case someone wants to change the values of Col_1 or Col_2 — if they change one of those values, then a column that held the combination of the two would also have to be updated. It makes things more complex than they need to be.
If you have some reason they must be in the database table, let us know.