List:General Discussion« Previous MessageNext Message »
From:Steve Edberg Date:September 14 2006 10:48pm
Subject:Re: Cloning or duplicating a record
View as plain text  
At 3:31 PM -0700 9/14/06, Scott Haneda wrote:
>  > how about:
>>  insert into <table_name> select * from <table_name> where <select
> criteria>
>>
>>  is the primary key an auto sequence?
>
>This is what happens when I try:
>insert into logbook select * from logbook where id = 1;
>ERROR 1062: Duplicate entry '1' for key 1
>--
>-------------------------------------------------------------
>Scott Haneda                                Tel: 415.898.2602
><http://www.newgeo.com>                     Novato, CA U.S.A.


YOu'll have to list the fields explicitly, except for the primary 
key. For example, if your table has columns:

id (PK)
data_1
data_2
data_3

you should be able to do

    insert into table_name (data_1, data_2, data_3) select 
data_1,data_2,data_3 from table_name where id=1

The insert failed because you were - as the error message said - 
trying to insert a record with an existing primary key, which is 
unique.

Check mysql manual for more info on syntax of insert command.

	steve

-- 
+--------------- my people are the people of the dessert, ---------------+
| Steve Edberg                                http://pgfsun.ucdavis.edu/ |
| UC Davis Genome Center                            sbedberg@stripped |
| Bioinformatics programming/database/sysadmin             (530)754-9127 |
+---------------- said t e lawrence, picking up his fork ----------------+
Thread
Cloning or duplicating a recordScott Haneda15 Sep
Re: Cloning or duplicating a recordhwigoda15 Sep
  • Re: Cloning or duplicating a recordScott Haneda15 Sep
  • Re: Cloning or duplicating a recordScott Haneda15 Sep
    • Re: Cloning or duplicating a recordSteve Edberg15 Sep
      • Re: Cloning or duplicating a recordScott Haneda15 Sep