备份和还原列值

时间:2010-11-02 10:23:56

标签: sql oracle

我需要对列值进行批量更新。如果有问题,我需要能够将列恢复为之前的值。所以我将值备份到临时表。

BTW,我正在使用Oracle。

CREATE TABLE tmp_trial_date_backup AS SELECT cust_id, trial_days FROM customer 
WHERE (trial_days = 0 or trial_days = -99) 

随后我将执行更新。

UPDATE customer SET trial_days = 1 WHERE (trial_days = 0 or trial_days = -99)

我的任务是......如何从我创建的tmp表中恢复列值?执行

2 个答案:

答案 0 :(得分:1)

以下更新会在SQL Server数据库上重置customer上的trial_days。

UPDATE  c
SET     trial_days = tmp.trial_days
FROM    customer c
        INNER JOIN tmp_trial_date_backup tmp ON tmp.cust_id = c.cust_id

可能更容易将列trial_days_backup添加到customer表。

答案 1 :(得分:1)

最后我做了以下事情。

UPDATE customer c SET trial_days = (SELECT trial_days from tmp_trial_days_backup 
where tmp_trial_days_backup.cust_id = customer_bond.cust_id)
WHERE EXISTS (SELECT 1 from tmp_trial_days_backup tmp WHERE tmp.cust_id = c.cust_id)