MySQL Forums
Forum List  »  General

Re: Concat Prefix with Id and autoincrement it uisng trigger in Mysql
Posted by: Peter Brawley
Date: March 18, 2014 04:28PM

It's not recommended. What problem are you trying to solve?

If you're determined to do it, the value assignment must be in a transaction. Then given a prefix column named `prefix` with a value 'foo' ...

start transaction;
  select @id := 1+max(id) from animals where prefix='foo' for update;
  insert into animals(foo, id, ...) values(foo, @id, ...)
commit;

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.