Select into without touching the autoincrement ID field

105 views Asked by At

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?

2

There are 2 answers

2
Michael Mairegger On BEST ANSWER

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
0
user1336827 On

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