數據庫update後的數據恢復

在開發過程中,我們有時候不注意,寫的腳本漏了where 條件或者因其他原因,導致數據更新錯誤,在沒有執行install語句前,可以根據時間點將數據恢復還原。

查詢修改的數據

select cert_cd from crm as of timestamp to_timestamp('2019-10-22 16:30:46','yyyy-mm-dd hh24:mi:ss');

1、修改還原單個字段的數據

update crm t1 set t1.cert = (select cert from crm as of timestamp to_timestamp('2019-10-22 16:30:46','yyyy-mm-dd hh24:mi:ss') where t1.sn = sn);

2、修改還原整個表數據

-- 查詢刪除的表數據
select * from 表名 as of timestamp to_timestamp('刪除時間點','yyyy-mm-dd hh24:mi:ss')

-- 把刪除的數據重新插入原表:
 insert into 表名 (select * from 表名 as of timestamp to_timestamp('刪除時間點','yyyy-mm-dd hh24:mi:ss'));
-- 注意要保證主鍵不重複。

-- 例如:
insert into TEST (select * from TEST as of timestamp to_timestamp('2020-01-16 17:30:46','yyyy-mm-dd hh24:mi:ss'));

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章