use next auto_increment id with ON DUPLICATE KEY?
Sure this must be simple, just not sure how to do it.
When replicating a row, how can I set the ON DUPLICATE KEY clause to update the PK with the next auto_increment id? I tried
...but it didn't like it.
insert into table select * from users where id = 1 on duplicate key update (select max(id)+1 from table)
Thanks in advance
say you have a table with columns
fldPersonID auto_incrementing primary key
then to duplicate the row with fldPersonID = 5 use:
and the newly inserted row will be allocated the next auto_incrementing value for fldPersonID.
insert into tblperson (fldFamilyName,fldGivenName)
from tblperson t
where t.fldPersonID = 5
Last edited by tirna; 04-15-2010 at 06:29 AM.
Thanks, I'll give it a go
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)