在SQL Sever 2008下,有两张表,一张prescription表,一张medicine表。prescription表有prescription_id、medicine_name、medicine_id等列,medicine表有medicine_id、medicine_name等列。我如何才能根据prescription表中的medicine_name自动生成prescription中的medicine_id呢?就是根据prescription表中的medicine_name查找到medicine表中medicine_id并将其填入到prescription表中的medicine_id中。有没有图形化的方法就是不用编程的那种,麻烦大家了。

解决方案 »

  1.   

    update b
    set medicine_id=a.medicine_id
    from medicine as a 
    inner join prescription as b on a.medicine_name=b.medicine_name
      

  2.   

    UPDATE A SET
      medicine_id = B.medicine_id
    FROM prescription A,medicine B
    WHERE A.medicine_name = B.medicine_name
      

  3.   


    update a 
    set a.medicine_id=b.medicine_id
    from prescription a
    inner join medicine b on a.medicine_name=b.medicine_name
      

  4.   

    update
     a 
    set
     medicine_id=b.medicine_id
    from
     prescription a, medicine b 
    where
     a.medicine_name=b.medicine_name