删除历史年度数据只保留091011三个年度.docx
《删除历史年度数据只保留091011三个年度.docx》由会员分享,可在线阅读,更多相关《删除历史年度数据只保留091011三个年度.docx(8页珍藏版)》请在冰豆网上搜索。
删除历史年度数据只保留091011三个年度
删除历史年度数据只保留091011三个年度
因为PMC计算等原因,每天起数据库2-3次或以上。
而新中大软件老厂帐套中,保留了多年的数据。
目标:
准备只保留09、10、11年度的数据,其余年度的数据,
如果测试备份可以删除后INSERT回来,则将会删除他们。
?
?
?
?
?
?
1、备份(数据库备份、新中大备份(开始删除之前的数据备份,开始删除数据之后的备份))
2、删除了哪些表的内容,截至日期
3、ID号?
?
?
以下使用的为lxz个人电脑上数据库中的数据。
其数据只保留到了2008年8月29日。
一、利用企业管理器备份数据库至E:
\李宪忠本机数据backup,时间为20110105
备份开始时间为22:
13
ng0001bf数据库
select*intong0001bf.dbo.ordermstfromng0001.dbo.ordermst
(所影响的行数为42467行)
selectcount(*)fromng0001.dbo.ordermst
select*fromordermst
selectsubstring(sysno,1,3),count(*)fromng0001.dbo.ordermstgroupbysubstring(sysno,1,3)
P05381
P0614833
P0718211
P089042
准备将05年及06年数据删除。
-----------------------------
-----------------------------
1ordermstorderdet
selectsubstring(sysno,1,3),count(*)fromorderdetgroupbysubstring(sysno,1,3)
select*fromordermst
wheresysnolike'P05%'orsysnolike'P06%'orsysnolike'P07%'orsysnolike'P08%'
deletefromordermst
wheresysnolike'P05%'orsysnolike'P06%'orsysnolike'P07%'orsysnolike'P08%'
deletefromorderdet
wheresysnolike'P05%'orsysnolike'P06%'orsysnolike'P07%'orsysnolike'P08%'
-----------------------------
selectsysnofromsendmst
wheresysnolike'Q05%'orsysnolike'Q06%'orsysnolike'Q07%'orsysnolike'Q08%'
orderbysysno
deletefromsendmst
wheresysnolike'Q05%'orsysnolike'Q06%'orsysnolike'Q07%'orsysnolike'Q08%'
deletefromsenddet
wheresysnolike'Q05%'orsysnolike'Q06%'orsysnolike'Q07%'orsysnolike'Q08%'
-----------------------------
selectsysnofromsbackdet
wheresysnolike'S05%'orsysnolike'S06%'orsysnolike'S07%'orsysnolike'S08%'
ORDERBYSYSNO
DELETEfromsbackdet
wheresysnolike'S05%'orsysnolike'S06%'orsysnolike'S07%'orsysnolike'S08%'
DELETEfromsbackmst
wheresysnolike'S05%'orsysnolike'S06%'orsysnolike'S07%'orsysnolike'S08%'
-----------------------------
deletefromsbillmst
wheresysnolike'S05%'orsysnolike'S06%'orsysnolike'S07%'orsysnolike'S08%'
deletefromsbilldet
wheresysnolike'S05%'orsysnolike'S06%'orsysnolike'S07%'orsysnolike'S08%'
selectsysnofromsbillmst
wheresysnolike'Q05%'orsysnolike'Q06%'orsysnolike'Q07%'orsysnolike'Q08%'
deletefromsbillmst
wheresysnolike'Q05%'orsysnolike'Q06%'orsysnolike'Q07%'orsysnolike'Q08%'
deletefromsbilldet
wheresysnolike'Q05%'orsysnolike'Q06%'orsysnolike'Q07%'orsysnolike'Q08%'
-----------------------------
selectspurnofrompurmst
wherespurnolike'G05%'orspurnolike'G06%'orspurnolike'G07%'orspurnolike'G08%'
deletefrompurmst
wherespurnolike'G05%'orspurnolike'G06%'orspurnolike'G07%'orspurnolike'G08%'
deletefrompurdec
wherespurnolike'G05%'orspurnolike'G06%'orspurnolike'G07%'orspurnolike'G08%'
-----------------------------
selectsrtnnofromrtnmst
wheresrtnnolike'J05%'orsrtnnolike'J06%'orsrtnnolike'J07%'orsrtnnolike'J08%'
deletefromrtnmst
wheresrtnnolike'J05%'orsrtnnolike'J06%'orsrtnnolike'J07%'orsrtnnolike'J08%'
deletefromrtndec
wheresrtnnolike'J05%'orsrtnnolike'J06%'orsrtnnolike'J07%'orsrtnnolike'J08%'
-----------------------------
selectsrecnofromrecmst
wheresrecnolike'205%'orsrecnolike'206%'orsrecnolike'207%'orsrecnolike'208%'
deletefromrecmst
wheresrecnolike'205%'orsrecnolike'206%'orsrecnolike'207%'orsrecnolike'208%'
deletefromrecdet
wheresrecnolike'205%'orsrecnolike'206%'orsrecnolike'207%'orsrecnolike'208%'
-----------------------------
selectsrcvnofromrcvmst
wheresrcvnolike'K05%'orsrcvnolike'K06%'orsrcvnolike'K07%'orsrcvnolike'K08%'
DELETEfromrcvmst
wheresrcvnolike'K05%'orsrcvnolike'K06%'orsrcvnolike'K07%'orsrcvnolike'K08%'
DELETEfromrcvdet
wheresrcvnolike'K05%'orsrcvnolike'K06%'orsrcvnolike'K07%'orsrcvnolike'K08%'
-----------------------------
selectordnofrommps_mfg_ord
whereordnolike'N05%'orordnolike'N06%'orordnolike'N07%'orordnolike'N08%'
ORDERBYordno
deletefrommps_mfg_ord
whereordnolike'N05%'orordnolike'N06%'orordnolike'N07%'orordnolike'N08%'
selectordnofrommps_mfg_det
whereordnolike'N05%'orordnolike'N06%'orordnolike'N07%'orordnolike'N08%'
deletefrommps_mfg_det
whereordnolike'N05%'orordnolike'N06%'orordnolike'N07%'orordnolike'N08%'
-----------------------------
selectordnofrommps_allocation
whereordnolike'N05%'orordnolike'N06%'orordnolike'N07%'orordnolike'N08%'
deletefrommps_allocation
whereordnolike'N05%'orordnolike'N06%'orordnolike'N07%'orordnolike'N08%'
-----------------------------
selectreq_nofrommrp_req_det
wherereq_nolike'R05%'orreq_nolike'R06%'orreq_nolike'R07%'orreq_nolike'R08%'
deletefrommrp_req_det
wherereq_nolike'R05%'orreq_nolike'R06%'orreq_nolike'R07%'orreq_nolike'R08%'
-----------------------------
selectsysnofrommdm_proc_reqdtl
wheresysnolike'U05%'orsysnolike'U06%'orsysnolike'U07%'orsysnolike'U08%'
deletefrommdm_proc_reqdtl
wheresysnolike'U05%'orsysnolike'U06%'orsysnolike'U07%'orsysnolike'U08%'
deletefrommdm_proc_reqmst
wheresysnolike'U05%'orsysnolike'U06%'orsysnolike'U07%'orsysnolike'U08%'
-----------------------------
selectbmordnofrommps_back_makeup
wherebmordnolike'2005%'orbmordnolike'2006%'orbmordnolike'2007%'orbmordnolike'2008%'
deletefrommps_back_makeup
wherebmordnolike'2005%'orbmordnolike'2006%'orbmordnolike'2007%'orbmordnolike'2008%'
-----------------------------
billbodybillhead
selecttransidfrombillhead
wheretransidlike'05%'ortransidlike'06%'ortransidlike'07%'ortransidlike'08%'
deletefrombillhead
wheretransidlike'05%'ortransidlike'06%'ortransidlike'07%'ortransidlike'08%'
deletefrombillbody
wheretransidlike'05%'ortransidlike'06%'ortransidlike'07%'ortransidlike'08%'
清除日志
DUMPTRANSACTIONNG0003WITHNO_LOG
再收缩日志文件大小
deletefrombillbody
wheretransidlike'07%'
deletefrombillbody
wheretransidlike'08%'
-----------------------------
invtory
selectuyearfrominvtory
whereuyear='2007'oruyear='2008'
deletefrominvtory
whereuyear='2007'oruyear='2008'