Question

I'm looking for a way I can duplicate all the rows in my database, I tried exporting it and then importing but I get the duplicate key error.

The reason is purely for testing purposes, I just want a load of dummy data in there to test the system I have out.

Is there a direct statement for this? Or is there a way to export all data except ID (or change ID to MAX(ID) + 1 or AUTO INCREMENT)?

Was it helpful?

Solution

You can try this:

INSERT INTO your_table_name(parent_id,priority,text,shortname,weighting,g_or_a,
     dept,ksf,day_start,day_end,date_start,date_end,depends_on,is_question,budget,
     ccode,responsible,accountable,consulted,informed)
(SELECT parent_id,priority,text,shortname,weighting,g_or_a,dept,ksf,
    day_start,day_end,date_start,date_end,depends_on,is_question,budget,ccode,
    responsible,accountable,consulted,informed FROM your_table_name);

Firstly, insert one row in the table 'your_table_name'. Replace your_table_name with the actual table name in above code & execute the code repeatedly until it satisfies the required row numbers. I think it should work.

OTHER TIPS

Put 1 record and then run:

insert into mytable select * from mytable

10 times. This will give you 1024 records. Continue until satisfied.

You could use an INSERT and the values would be a SELECT, just don't select the primary key and don't define it in the insert fields.

Imagine a table with 3 fields, the_pk, field_1, field_2

Something like

INSERT INTO the_table(field_1, field_2) (SELECT field_1, field_2 FROM the_table)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top