1. 备份日志, 避免日志过快增长 no_log / trancate_only BACKUP LOG realnew_DATA WITH NO_LOG BACKUP LOG sjyh WITH NO_LOG 2. 维持历史库数据表中的记录不超过5000条, 并将实时库中数据插入历史库 if ((select count(tag_id) from CalcOUT_1_HIS)>3000) go 然后,添加作业 2) 使用触发器--针对表一级的 CREATE TRIGGER deleterecord ON [dbo].[testtrigger]
DBCC SHRINKDATABASE(realnew_DATA ,TRUNCATEONLY)
BACKUP LOG realnew_DATA WITH Truncate_ONLY
DBCC SHRINKDATABASE(sjyh,TRUNCATEONLY)
BACKUP LOG sjyh WITH Truncate_ONLY
1) 使用存储过程 --作业
CREATE procedure insert_calHistory as
begin
delete from CalcOUT_1_HIS where tag_id in (select top 500 tag_id from CalcOUT_1_HIS order by tag_id)
end
insert into CalcOUT_1_HIS select * from CalcOUT_1_REAL
调度:每天每隔3分钟执行一次
SQL: exec insert_calHistory
after INSERT
AS
IF
(SELECT COUNT(*) FROM testtrigger) >5000
BEGIN
DELETE FROM testtrigger where id not in ( select top 300 id from testtrigger order by id desc)
END
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073