需求:将两张数据结构一致的表合并成第三章表

步骤:1.创建一张新的表(不带主键)

           2.将两张表中的数据插入到新表中(插入数据时过滤掉主键)

             insert into u5  (name) select name from a2;

             insert into u5  (name) select name from a3;

          3.修改第三张表(增加一列主键)

             alter table u5 add column num int primary key auto_increment first;

            注:这里使用auto_increment自增长避免主键冲突

                   使用first将主键列放在第一列

           另:为什么不在第一步的时候将表的主键列建好?

                  因为是将两张表合并到第三张表中,需香第三张表中插入两次数据,如果在第一步的时候将表的主键列建好,这样会导致主键不连续

             

相关文章:

  • 2021-10-20
  • 2022-03-10
  • 2021-12-07
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 1970-01-01
  • 2021-12-04
  • 2022-12-23
  • 2019-07-21
  • 2022-12-23
相关资源
相似解决方案