【问题标题】:How to insert data from dump file to another table with different data structure?如何将转储文件中的数据插入到具有不同数据结构的另一个表中?
【发布时间】:2016-01-18 10:53:10
【问题描述】:

我有两个表 tb1(列 c1、c2、c3、c4、c5...)和 tb2(列 C1、C2、C3、C4、CN4、C5、CN6),Tb2 与 tb1 的架构描述相同,但我更改了 tb2 添加更多列,我的问题是:我可以从 tb1 转储数据,然后将其插入到 tb2 即使此表使用 mysqldump 进程有更多列?

【问题讨论】:

    标签: mysql database-schema mysqldump


    【解决方案1】:

    您可以像下面那样执行insert into ... select from,而不是从转储文件插入。请注意:这仅在 CN4CN6 是可为空的列时才有效(它们没有 not null 约束)。

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

    【讨论】:

      猜你喜欢
      • 2017-12-21
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      • 2019-03-17
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      相关资源
      最近更新 更多