Use REPLACE instead of INSERT

by Sanju 2008-07-03 18:41:12


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

Tagged in:

2031
like
0
dislike
0
mail
flag

You must LOGIN to add comments