我有数据库A和B,里面都有user 表,假设A库的user表里type这个字段,需要再B库的user表加1个ype字段,怎么用代码实现,php c#都行,因为我要合并数据库,首先保证B数据库的每个表的字段要和A库保存一致

解决方案 »

  1.   


    关联修改下,语句如下:
    UPDATE B.user bb INNER JOIN A.user aa ON bb.id = aa.id SET bb.type = aa.type WHERE bb.name = aa.name AND bb.age = aa.age;
    将A数据库中的user 表的type 值修改为 B数据库中的user表的type值,条件是两个表的主键相同,并且name字段和age字段相同。
      

  2.   

    用php 执行这条sql语句,具体参数自己修改
    alter table `user` add column type int(8) not null default 0 after `time`
      

  3.   

    update B.user set B.user.type=(select A.user.type from A.user where id=B.user.id);