Can I Import an updated structure into a MySQL table without losing its current content?

后端 未结 6 1590
南旧
南旧 2021-02-08 01:30

We use MySQL tables to which we add new fields from time to time as our product evolves. I\'m looking for a way to export the structure of the table from one copy of the db, to

6条回答
  •  佛祖请我去吃肉
    2021-02-08 02:15

    for your case, it might just need to perform an update

    alter table B add column x varchar(255);
    alter table B add column y varchar(255);
    alter table B add column z varchar(255);
    
    update A,B 
    set 
      B.x=A.x,
      B.y=A.y,
      B.z=A.z
    where A.id=B.id; <-- a key that exist on both tables
    

提交回复
热议问题