2个表, A表有AID,N,X 3个字段. B表上有BID,N,Y 3个字段.
N为2个字段的关联字段
现要把BID字段的更新为AID,SQL语句怎样写?

解决方案 »

  1.   

    update b set bid = aid
    from a
    where a.n = b.n
      

  2.   

    update A set AID=(select BID from B where B.N=A.N)
    from(
    select * from B 
    )B 
    where A.N=B.N
      

  3.   


    create table A(AID int, N int, X char(1))
    insert A select 1, 1, 'a'
    union all select 2, 2, 'b'
    union all select 3, 3, 'c'create table B(BID int, N int, Y char(1))
    insert B select 4, 1, 'a'
    union all select 5, 2, 'b'
    union all select 6, 3, 'c'update A set AID=B.BID
    from(
    select * from B 
    )B 
    where A.N=B.N
      

  4.   

    谢谢楼上.update b set bid = (select a.aid from a)
    where a.n = b.n
    我这样写,报错到我郁闷了...