有表A,B.具有相同ID.表A有列ID,NAME表B有列ID,CLASS现在如何把表B变成ID,CLASS,NAME这种.表A,B的ID列内容完全一样.谢谢.

解决方案 »

  1.   

    SELECT B.ID ,A.CLASS,B.NAME 
    FROM B LEFT JOIN A 
    ON B.ID = A.ID 
      

  2.   

    alter table B add Name varchar(20)
    GO
    update B set b.Name=a.name from A where a.id=b.id
      

  3.   


    alter table B add Name varchar(20)
    GO
    update B set b.Name=a.name from A where a.id=b.id
      

  4.   

    select a.id,b.class,a.name into tmp from ta a ,tb b  where a.id = b.id drop table tbsp_rename ..
      

  5.   

    select ID,Class,Name into ## from A join B on a.id=b.id
    drop table A
    select * into A from ##
    drop table ##
      

  6.   

    添加列:alter table B add [NAME ] nvarchar(50)
    插入值:insert into B ([name]) select [name] from A
      

  7.   

    添加列:alter table B add [NAME ] nvarchar(50)
    插入值:update B set b.Name=a.name from A where A.id=B.id
      

  8.   

    --将目标数据放入新表TB中
    SELECT A.ID,CLASS,NAME 
    INTO TB 
    FROM B LEFT JOIN A 
    ON B.ID = A.ID --删除B表
    drop table B--然后重命名TB表为B
    EXEC sp_rename 'TB', 'B';
      

  9.   

    SELECT B.ID ,A.CLASS,B.NAME 
    FROM B LEFT JOIN A 
    ON B.ID = A.ID --查询
      

  10.   


    if exists(select 1 from dbo.syscolumns where id=object_id('b') and name='class')--先判断CLASS列在表中是否存在
    alter table B add [class] nvarchar(50)