前一陣子在實施中發現問題,需要當時進行修改,而因為數據庫中數據是真實數據,不能進行修改,否則會出大纰漏吧,於是添加測試數據來方便修改,而單個添加效率太低下了,所以解決的辦法就是以真實的數據為模板增添新方便刪除的數據即可,就像將2014年的數據復制一份只將年份進行修改,刪除的時候講這個不存在的年份數據刪除即可。
相信大家很容易會想到這個方法,也很容易做出答案,舉個例子:

看這個表,因為主鍵中都是以當年年份開頭的,同時年度也是當年年份,這樣我們就可以進行添加修改:
假使說這個表格存在如下列:
btfid、production、code、retrieveid、location、tobaccostation、plantvillage、cooperation、tobaccotechnician、eastlong、eastlat、southlong、southlat、westlong、westlat、northlong、northlat、amsl、totalarea
那樣我們可以可以這樣寫:
insert into
arc_basictobaccofield
select '2016' || substr(btfid, 5),
'2016',
code,
retrieveid,
location,
tobaccostation,
plantvillage,
cooperation,
tobaccotechnician,
eastlong,
eastlat,
southlong,
southlat,
westlong,
westlat,
northlong,
northlat,
amsl,
totalarea
from arc_basictobaccofield
where tobaccostation = '37030405C'
and productionyear = 2015
答案是肯定的,這樣我們倒過來思考下,我們只需要修改兩列而已,那我們就把所有數據取出來,將這兩列數據修改之後進行插入不就可以了麼,我們來寫下看:
首先我們來創建一個臨時表:
create table arc_basictobaccofield1 as select * from arc_basictobaccofield where tobaccostation='37030405C' and productionyear=2015
update arc_basictobaccofield1 set productionyear=2015 update arc_basictobaccofield1 set btfid ='2015'||substr(btfid,5)
insert into arc_basictobaccofield select * from arc_basictobaccofield1
drop table arc_basictobaccofield1