I currently have a table with an id column that is being autoincremented and then there’s a tracking_code column that has a unique constraint on it.
Currently the tracking_code is being supplied by the person signing up, but now the client wants that tracking_code to be auto-generated yet be changeable as well.
In other words, where a user signs up, auto-generate the tracking_code, but allow the user to update that code to anything else as long as it stays unique.
Is it possible to do something like this in MySQL (append a string to an autoincremented id which only exists after the record is inserted) or is there another way of doing it in mysql:
INSERT INTO mytable (…, tracking_code, …) VALUES (…, ‘foo-‘ + id + ‘-bar’, …)
You can do this:
Or
Obviously only works if you have an
AUTO_INCREMENTcolumn.