mysql - Duplicate all rows in a table and prevent duplicate keys -


i tring this

  • get rows in blogs named table.
  • copy them in temporary database
  • edit language field of temporary table records
  • insert blogs table

and i'm trying this:

create temporary table tmptable select * blogs lan = 2; update tmptable set lan = 1; insert blogs select * tmptable; dump database tmptable; 

but of corse duplicated key error...

how can prevent it?

-edit-

i tried:

create temporary table tmptable select * blogs lan = 2; update tmptable set lan = 1; alter table tmptable drop id; insert blogs select * tmptable; dump database tmptable; 

but column count doesn't match value count @ row 1

-edit-

i believe work (and did, cause know how many records exist)

create temporary table tmptable select * blogs lan = 2; update tmptable set lan = 1; update tmptable set id = id + 1000; insert blogs select * tmptable; 

but how can properly? (just set next avaliable autoincrement value primary key(id) (without php/alike))

-edit-

maybe this???

create temporary table tmptable select * blogs lan = 2; update tmptable set lan = 1; update tmptable set id = id + (select id blogs order id desc limit 1); insert blogs select * tmptable; 

create temporary table tmptable select * blogs lan = 2; update tmptable set lan = 1; alter table tmptable drop column id; insert blogs select null,tmptable.* tmptable; 

assumed, column "id" first col.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -