update AA ?????????? where  AA.id in BB.id and AA.code in BB.code 如何将表AA中与表BB中id一样的行的数据照BB表中的数据做更新,可不可不需要写每个字段  AA与BB表的表结构是完全一样的

解决方案 »

  1.   

    1、必须要把更新的字段都写清楚,及时表结构是一样的。update AAA
    set a.name = b.name ,a.sex = b.sex ,......
    from AAA a join BBB b on a.id = b.id and a.code = b.code
      

  2.   

    1.字段是要写清楚的,超越语法的事情,可以去想,但不要去做了。呵呵
    2.对于比较复杂的update,如果编程时没有数据库移植的问题,强烈建议使用MERGE来进行。
      

  3.   

    update a set(col1,col2,col3...)=(select col1,col2,col3... from b where a.id=b.id);
    SQL> create table t as select * from emp where 1=0;表已创建。SQL> insert into t(empno) values(1);已创建 1 行。SQL> insert into t(empno) values(7369);已创建 1 行。SQL> insert into t(empno) values(7934);已创建 1 行。SQL> update t set(ename,job)=(select ename,job from emp where emp.empno=t.empno);已更新3行。SQL> select * from t;     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM     DEPTNO
    ---------- ---------- --------- ---------- -------------- ---------- ---------- ----------
             1
          7369 SMITH      CLERK
          7934 MILLER     CLERKSQL>