Use REPLACE instead of INSERT - Mysql Views : 899
Tagged in : Mysql
0 0
Send mail

I have created two tables xx and yy. When i am trying to copy the records from one the table xx to yy i got an error:

ERROR 1062: Duplicate entry '1' for key 1

Why?

mysql> CREATE TABLE xx(id int(11) PRIMARY KEY auto_increment, Name VARCHAR(20));

mysql> CREATE TABLE yy(id int(11) PRIMARY KEY auto_increment, Name VARCHAR(20));

I have also inserted the values for two tables.

mysql> INSERT INTO yy(Name)SELECT Name FROM xx;
ERROR 1062: Duplicate entry '1' for key 1

But this works:

mysql> REPLACE INTO yy(Name)SELECT Name FROM xx;

When you got an error ERROR 1062: Duplicate entry '1' for key 1 while copying the records use REPLACE instead of INSERT
By Sanju, On - 2008-07-03



    Login to add Comments .