Question

I want to migrate data from one table to another without copying the autoincremented ID field.

source_table:

ID LABEL

-- -----

5 text

6 text2

dest_table:

ID LABEL

-- -----

SELECT LABEL
INTO dest_table
FROM source_table

Will the above statement work knowing that ID in dest_table is an auto-incremented primary key?

Was it helpful?

Solution

Yes, it will work ans result in

1 text

2 text2

But the problem is if you have a second table that is created and will referece to the created on. Then you have to leave the values of the primary keys as they are and not ignore them.

The query is not correct:

INSERT INTO destination (label) SELECT label FROM source

OTHER TIPS

Yes it will work fine, the auto increment in the new table will just auto increment.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top