Angel Humberto Vargas
Angel Humberto Vargas

Reputation: 122

How to insert data from dump file to another table with different data structure?

I have two tables tb1 (Columns c1, c2, c3, c4, c5...) and tb2 (Columns C1, C2, C3, C4, CN4, C5, CN6), Tb2 was the same schema description as tb1, but I altered tb2 adding more columns, my question is: could I dump data from tb1 and then insert it to tb2 even this table have more columns using mysqldump process?

Upvotes: 1

Views: 246

Answers (1)

Rahul
Rahul

Reputation: 77866

Instead of inserting from dump file, you can just do a insert into ... select from like below. Point to notice: this would work only if CN4 and CN6 are nullable columns (they don't have a not null constraint on them).

insert into tb2(C1, C2, C3, C4, CN4, C5, CN6)
select C1, C2, C3, C4, null, C5, null
from tb1;

Upvotes: 1

Related Questions