說明:IbosExecHistory系列表是提供歷史數(shù)據(jù)查詢的歷史表;
IbosExecHistory為試圖;
IbosExecHistory_XXXX中“XXXX”為年份,供存放該年所有歷史數(shù)據(jù),此類表做歷史數(shù)據(jù)備份用,不提供維護(hù)系統(tǒng)查詢;
IbosExecHistory_month_X中“X”為月份(1-9不加0),此類表做循環(huán)使用,根據(jù)維護(hù)系統(tǒng)要求查詢時(shí)提供6個(gè)月內(nèi)數(shù)據(jù),故在此前六個(gè)月之外的數(shù)據(jù)可清楚。最后及時(shí)清楚,否則將造成與往年數(shù)據(jù)共存現(xiàn)象,較難分離。若造成累計(jì),建議將數(shù)據(jù)使用bcp導(dǎo)出后,對(duì)文件進(jìn)行操作,不要在數(shù)據(jù)庫中進(jìn)行操作。
工作原理:為減少對(duì)數(shù)據(jù)庫性能造成影響,使用bcp和truncate table操作,做truncate table時(shí)應(yīng)謹(jǐn)慎。
本文目的:提供IbosExecHistory_month_X表歷史數(shù)據(jù)清除步驟。
注:以下步驟以2010年5月份歷史數(shù)據(jù)清除為例,在實(shí)際操作中需更改重要sql語句,謹(jǐn)記。
具體步驟:
1.查詢年份表中是否已有該月數(shù)據(jù),結(jié)果為0,則順序執(zhí)行
select count(*) from IbosExecHistory_2010 where SendTime>='2010-05-01' and SendTime<'2010-06-01'
2.查詢?cè)路荼碇惺欠褚亚宄Y(jié)果不為0,則順序執(zhí)行
select count(*) from IbosExecHistory_month_5
3.使用bcp命令進(jìn)行數(shù)據(jù)導(dǎo)出,bcp命令OS命令,在已安裝sybase數(shù)據(jù)庫客戶端的系統(tǒng)上方可使用
bcp test..IbosExecHistory_month_5 out d:\IbosExecHistory_month_5.txt -c -t "{" -r "\r\n" -Uibos -Pibos123 -Stfh28
4.使用bcp命令進(jìn)行數(shù)據(jù)導(dǎo)入
bcp test..IbosExecHistory_2010 in d:\IbosExecHistory_month_5.txt -c -t "{" -r "\r\n" -Uibos -Pibos123 -Stfh28
5.清除月份表數(shù)據(jù)
truncate table IbosExecHistory_month_5