I have a MySQL table that has an auto incrementing primary call and a UUID. Both serve as unique IDs, as there are two tables with similar objects and there needs to be a unique identifier across both tables (and possible more objects still).
So table looks:
table A
_______
ID int pk, ai
UUID varchar, uq
other columns....
The application will insert into this table, but chances are that it won't always have a UUID generated. Sometimes the application provides the UUID, sometimes I need MySQL to create one.
How can that be achieved? - I have tried with this trigger:
CREATE TRIGGER trig_ains_aw_trckid
AFTER INSERT ON table_a
FOR EACH ROW
begin
update table_a set UUID = (SELECT concat('k_', uuid())) where UUID is null;
end
Now I cannot insert into the table, as the trigger seems to be sitting in front of it:
Can't update table 'account_keywords' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Any help would be most appreciated and any explanation as to what I'm doing wrong even more so. Without stating the obvious, the UUID should obviously stay the same... Having not needed to use Triggers before, I think I do not know much about them. In MS SQL this was actually quite easy!
Thanks,
Chris