|
|
Use REPLACE instead of INSERT - Mysql
|
Views : 899
|
|
Tagged in : Mysql
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
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 |
|
|
|