table1         table2
ID   NAME     ID   NAME  WORK
1     a       1           teacher
2     b       2           student 
3     c       3           student
4     d       4           teacher
...
其中ID唯一如何UPDATE使table2为
ID   NAME    WORK
1     a      teacher
2     b      student 
3     c      student
4     d      teacher
...

解决方案 »

  1.   

    ~~================================================================
         ◆◆◆ CSDN查询助手,查询方便快捷◆◆◆ 下载地址:  
     http://CoolSlob.ifood1.com/Download/CSDNFinder.exe  
     http://CoolSlob.8u8.com/Download/Tools/CSDNFinder.Slob[更名为.exe即可]  
      

  2.   

    update table2
    set name = b.name
    from table2 a join table1 b on a.id = b.id
      

  3.   

    如果是Oracle可用PL/SQL
    declare 
      cursor exam is select ID,NAME from Table1; 
      vID   Table1.ID%TYPE;
      vNAME Table1.NAME%TYPE;
    begin  open exam;
      loop
      
        fetch exam into vID, vNAME;    update Table2
        set NAME=vNAME
        where ID=vID;
        
        exit when exam%NOTFOUND;
        
      end loop;
      close exam;
      
    end;
      

  4.   

    用游标,不过我不知道pardox的游标怎么用,你编一个程序,用一个循环不就行了。
      

  5.   

    哈哈:)
    楼主在搞笑呀?!Paradox:
      你可以使用Table全部找出来,e.g.
      Table1 -> 对应 Table1表
      Query1 -> 对应 Table2表Table1.Open;
    Table1.First;
    while not Table1.Eof do
    begin
      Query1.SQL.Text := Format('Update Table1 Set Name=%s Where ID=%d', [Table1.FieldByName('Name').AsString, Table1.FieldByName('ID').AsInteger]);
      Query1.ExecSQL;
      Table1.Next;  
    end;大概这样,上面的代码没有调试,自己看看吧~~================================================================
         ◆◆◆ CSDN查询助手,查询方便快捷◆◆◆ 下载地址:  
     http://CoolSlob.ifood1.com/Download/CSDNFinder.exe  
     http://CoolSlob.8u8.com/Download/Tools/CSDNFinder.Slob[更名为.exe即可]  
      

  6.   

    更正:Format('Update Table2 Set Name=%s Where ID=%d', [Table1.FieldByName('Name').AsString, Table1.FieldByName('ID').AsInteger]);刚才Update到了Table1了,呵呵:)
    ================================================================
         ◆◆◆ CSDN查询助手,查询方便快捷◆◆◆ 下载地址:  
     http://CoolSlob.ifood1.com/Download/CSDNFinder.exe  
     http://CoolSlob.8u8.com/Download/Tools/CSDNFinder.Slob[更名为.exe即可]  
      

  7.   

    更正:Format('Update Table2 Set Name=%s Where ID=%d', [Table1.FieldByName('Name').AsString, Table1.FieldByName('ID').AsInteger]);刚才Update到了Table1了,呵呵:)
    ================================================================
         ◆◆◆ CSDN查询助手,查询方便快捷◆◆◆ 下载地址:  
     http://CoolSlob.ifood1.com/Download/CSDNFinder.exe  
     http://CoolSlob.8u8.com/Download/Tools/CSDNFinder.Slob[更名为.exe即可]  
      

  8.   

    CoolSlob() 想法不错,但是不可用!
      

  9.   

    Update table2 set name=b.name
    from table2 a 
    inner join table1 b on a.id = b.id
      

  10.   

    为什么不可用??!================================================================
         ◆◆◆ CSDN查询助手,查询方便快捷◆◆◆ 下载地址:  
     http://CoolSlob.ifood1.com/Download/CSDNFinder.exe  
     http://CoolSlob.8u8.com/Download/Tools/CSDNFinder.Slob[更名为.exe即可]