product表里有kind列,字符型
product_kind里有id自增列和kind字符型列
这两个列是关系型的现在要求将product表里的kind列变成product_kind的id指向,即不直接存文字了,要改成存ID的,ID就是product_kind里的ID,如何做到一次性更改?

解决方案 »

  1.   

    update product set kind=k.id  from product_kind k where product.kind=k.kind
    goalter table product alter column kind int
    go
      

  2.   

    update a set kind = rtrim(b.id) 
    from product as a
    inner join product_kind as b
    on a.kind = b.kind
      

  3.   


    update a set kind =b.id 
    from product a 
    join product_kind on a.kind=b.kind
      

  4.   

    update a set kind =b.id 
    from product a 
    join product_kind b on a.kind=b.kind居然海写措了...不好意思..
      

  5.   

    alter table product add column kindid int
    go
    update a
    set a.kindid = b.id
    from product a join product_kind b on a.kind = b.kind
    go
    alter table product drop column kind