通常你好备份数据需要放到另一个表中,这样就不会造成混乱.
1.建立Table1_backup2.建立trigger , 当update Table1 时, insert old record to Table1_backup .如果你不这样做,你的数据库会变得一团糟:-)

解决方案 »

  1.   

    一、通常我不需要备份这样的数据,只在极特殊的情况下需要备份(而且是手动操作的,并不是有更新就需要备份,这是出于特殊情况考虑的,与通常意义上的数据库备份是不一样的)???????:没有说新建一个表就是通常意义的备份!!如果你是手工备份的话,那就没有必要修改程序了,你什么都不需要作了!!二、即使备份到另一个表中,数据在备份后又要如何恢复呢?这又回到了如何在表中插入一条与已有数据几乎完全一样的数据(除主键外)的问题????????:怎么说一样呢?如果几乎一样,备份就没有意义了,既然备份了,就肯定可以恢复,
    delete table1 where no='001';
    insert into table1 select * from table1_bak where no='001';
      

  2.   

    建一个viewcreate or replace back_view
    select no||'_BACK' as no_back , other_column, ....
    from yourtable;insert into yourtable (select * from back_view where no_back='001_BACK');
      

  3.   

    请各位老大在帮我提供解决方案时,不要偏离一个主题:原数据和备份数据一定要在一个表里,而且已经在一个表里了。所以备份到另一个表不是我要问的问题,也不能靠建立视图来进行备份,不要批判我的做法,不要管它合不合理,就单纯的解决这个问题sql语句应该怎么写?现在表里已经有这样的数据了:
             No           Name   Age    Address
             001          张三   25     沈阳市和平区文化路115号
             001_BACK     张三   25     沈阳市和平区文化路115号现在我要恢复数据了,先删除“001”的数据,然后用insert into table1 (select '001',Name,Age,Address from table1 where No='001_BACK'),这样就可以把备份的数据恢复了。但是必须写出所有的字段Name,Age,Address,如果一个表里的字段非常非常多的话,就很麻烦。特别是当数据库的结构没有完全定下来的时候。如果没有主键的话,就好办了。insert into table1 (select * from table1 where No='001_BACK'),不需要具体的知道有些什么字段。有没有什么方法,能够修改主键还不需要具体的知道所有字段的,如第二个语句,就很好,偏偏需要修改主键才能插入(只要有一个字段需要改变的话,就需要写出所有其它的字段)。
    最后再提醒一句:一定要在同一个表里
      

  4.   

    借助创建临时表:
    Step 1
     delete from table1 where no='001';
    Step 2
     create temp_table as select * from table1 where no='001_BACK';
    Step 3
     update table1 set no='001' where no='001_BACK';
    Step 4
     insert into table1 ( select * from temp_table where no='001_BACK'); 
     -- 也可以不用 where 条件
    Step 5
     drop temp_table;这样就可以不用关心表中除主键外的其他字段了,Step1-5可以封装在匿名块之中执行。
      

  5.   

    step1 : rename tableaa to tabletmp;
    step2 : create table tableaa as select * from tabletmp;
    step3 : update tableaa set field=field||'_bak';
    step4 : insert into tableaa select * from tabletmp;
    step5 : drop table tabletmp;