我有两个表 
A表                          B表tempid    name              pid  name  tempid
--------------------        ----------------------------
12                          xb001  a     12          
13                          xb002  b     13
14                          xb003  d     14
15                          xb004  e     15我想将A表中的tempid ,name字段的值更新为B表中  PID,name的值,请教如何作到。由于数据量很大,我的做法实在是太慢了,求教高手多谢了

解决方案 »

  1.   

    update a
    set name = b.name 
    from a , b
    where a.tempid  = b.tempid 
      

  2.   


    update a
    set name = b.name ,
        tempid = b.pid
    from a , b
    where a.tempid  = b.tempid 
      

  3.   

    update 
      a
    set 
      name = b.name 
    from 
      a , b
    where 
       a.tempid  = b.tempid
      

  4.   

    tempid     name       
    ---------- ---------- 
    xb001      a
    xb002      b
    xb003      d
    xb004      e(所影响的行数为 4 行)
      

  5.   

    create table a(tempid varchar(10),   name varchar(10))
    create table b(pid varchar(10), name varchar(10), tempid varchar(10))
    insert into a (tempid) values(12)
    insert into a (tempid) values(13)
    insert into a (tempid) values(14)
    insert into a (tempid) values(15)insert into b values('xb001' , 'a'  ,  12 )         
    insert into b values('xb002' , 'b'  ,  13 )
    insert into b values('xb003' , 'd'  ,  14 )
    insert into b values('xb004' , 'e'  ,  15 )update a
    set name = b.name ,
        tempid = b.pid
    from a , b
    where a.tempid  = b.tempid select * from adrop table a , b