-- 初始化配置表
if object_id('t_sz_backup_tables') is not null
drop table t_sz_backup_tables
go
create table t_sz_backup_tables(
tableName varchar(60),
datetype int,
begintime datetime null,
endtime datetime null,
status int null,
redes varchar(200) null,
indestatus int null,
order_no int null,
isused int default 1)
go
create unique index inx_uni on t_sz_backup_tables(tableName)
go
insert into t_sz_backup_tables(tableName,datetype,order_no) values('t_zbk_o2didf_ck',2,1)
-- 程序
if object_id('fn_backup_tables') is not null drop procedure fn_backup_tables go create procedure fn_backup_tables( @datadate char(8), @datetype integer, @reccount integer output, @usedtime integer output, @retcode integer output, @retdesc char(200) output) /*--******************************************************************************************************************/ -- 功能说明: -- 读取配置表获取需要备份的表名,备份数据到 表名+yyyymm[dd] 表中 -- 参数说明: -- 1、输入 -- @datadate 会计日期 --*******************************************************************************************************/ as declare @tableName varchar(60) -- 源表表名 declare @cursorcount int -- 循环总数 declare @i_count int -- 循环变量 declare @c_backupName varchar(70) -- 备份表名 declare @c_exesql varchar(1000) -- 动态语句 declare @i_zq int -- 执行周期 : 1 每天 2每月 3每季 4每年 declare @i_datetype int -- 游标变量 declare @i_errorNum int -- 错误数量统计 declare @dt_begintime datetime -- 处理开始时间 declare @dt_endtime datetime -- 处理结束时间 begin --**************变量定义及初始化************************************************************************************* -- 定义局部变量 select @dt_begintime = getdate() -- 如果年最后一天 @i_zq = 4 if year(dateadd(day,1,@datadate))=year(@datadate)+1 select @i_zq = 4 -- 如果季度最后一天 @i_zq = 3 else if Quarter(dateadd(day,1,@datadate))<>Quarter(@datadate) select @i_zq = 3 -- 如果月最后一天 @i_zq = 2 else if month(dateadd(day,1,@datadate))<>month(@datadate) select @i_zq = 2 -- 否则@i_zq = 1 即每天执行 else select @i_zq = 1 select @retcode = 0 select @i_errorNum = 0 -- 根据执行日期是否为年末、季末、月末确定需备份的表 select tableName,datetype ,rank()over(order by order_no) as rankno into #temp from t_sz_backup_tables where isused = 1 and (status <> 0 or status is null) and datetype <= @i_zq -- 初始化循环变量 select @i_count = 1 select @cursorcount = count(1) from #temp while (@i_count<=@cursorcount) begin -- 获取表名 select @tableName = tableName,@i_datetype = datetype from #temp where rankno = @i_count select @reccount = 0 update t_sz_backup_tables set begintime = getdate(),status=null,endtime=null,redes=null where tableName = @tableName if object_id(@tableName) is not null begin -- 生成备份表名 if @i_datetype = 1 select @c_backupName = @tableName+'_'+@datadate else select @c_backupName = @tableName+'_'+substring(@datadate,1,6) -- 备份表存在则删除——获取最新表结构 if object_id(@c_backupName) is not null begin select @c_exesql = 'drop table '+@c_backupName execute (@c_exesql) -- 异常检测 select @retcode = @@error,@reccount = @reccount+@@rowcount if @retcode<>0 begin update t_sz_backup_tables set status=1,endtime=getdate(),redes='drop table '+@c_backupName+' failed!' where tableName = @tableName select @i_errorNum = @i_errorNum +1 select @i_count = @i_count + 1 continue end end -- 创建备份表 select @c_exesql = 'select * into '+@c_backupName +' from '+@tableName +' where 1=2' execute (@c_exesql) -- 异常检测 select @retcode = @@error,@reccount = @reccount+@@rowcount if @retcode <>0 begin update t_sz_backup_tables set status=1,endtime=getdate(),redes='create table '+@c_backupName+' failed!' where tableName = @tableName select @i_errorNum = @i_errorNum +1 select @i_count = @i_count + 1 continue end -- 备份数据到历史表 select @c_exesql = 'insert into '+@c_backupName+' select * from '+@tableName execute (@c_exesql) -- 异常检测 select @retcode = @@error,@reccount = @reccount+@@rowcount if @retcode<>0 begin update t_sz_backup_tables set status=1,endtime=getdate(),redes='insert into '+@c_backupName+' failed!' where tableName = @tableName select @i_errorNum = @i_errorNum +1 select @i_count = @i_count + 1 continue end -- 执行成功记录日志 update t_sz_backup_tables set status=0,endtime=getdate(),redes='backup into '+@c_backupName+' success!' where tableName = @tableName end else begin update t_sz_backup_tables set status = 1,endtime=getdate(),redes = convert(char(20),getdate(),120)+':backup failed!source table '+@tableName+' not found!' where tableName = @tableName select @i_errorNum = @i_errorNum + 1 select @i_count = @i_count + 1 continue end select @i_count=@i_count+1 end --*******3.<操作结束,退出>******************************************************************************* select @dt_endtime = getdate() select @usedtime = datediff(ss,@dt_begintime,@dt_endtime) if @i_errorNum <>0 begin select @retcode = 1 select @retdesc = convert(char,@i_errorNum)+' tables backup failed,'+convert(char,@cursorcount-@i_errorNum)+' backup success,please check up the table t_sz_backup_tables!' return @retcode end else begin select @retcode = 0 select @retdesc = convert(varchar,@dt_endtime,120)+':procedure fn_backup_tables '+convert(char,@cursorcount)+' tables was backuped success!' return @retcode end end go
相关推荐
windows下的sybase iq安装文档
Sybase IQ单表卸载和装载,可以解决null问题。
在linux平台上对 SybaseIQ数据库备份与恢复操作超详细介绍,一步接一步简单明了,供大家参考。
在LINUX操作系统中安装SybaseIQ数据库(服务器或客户端),总是会报这样那样的错误,其原因大都是因为缺少某些库文件(文件后缀为.so, 类似于Windows系统中的.dll文件)。本帖分享的“LINUX系统安装SybaseIQ数据库所...
sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3sybaseIQ KB3
支持sybase iq 16 数据库连接驱动 jconn2.jar 在jdk1.5下是好用的 jconn3.jar 未测试 jconn4.jar 在jdk1.6下是好用的 连接串: jdbc:sybase:Tds:127.0.0.1:2638/iqdemo
下载链接在附件中,SybaseIQ 12.7 for Windows
Window 安装参考SybaseIQ15.1安装和配置指南forWindows.pdf 3.3 linux安装 1.关闭防火墙 service iptables stop chkconfig iptables off sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
Sybase IQ是一个强大的即席查询服务器。用Sybase IQ来分离决策支持系统(DSS,Decision Support System,READER)和在线事务处理系统(OLTP,OnLine Transaction Processing,WRITER)。目前Sybase IQ在SG186数据中心...
常规和频繁的备份是针对数据库或设备故障提供保护的唯一... 对新数据库运行完全备份以提供一个基点, 然后按照固定的时间表进行完全备份 和增量备份。考虑时间和存储要求。平衡创建备份所需的时间和恢复数据所需的时间
提供了用于在 SybaseIQ中处理大对象 (LOB) 数据的参考资料
SybaseIQ数据库64位Windows系统服务器v16.0安装包,可选择Express Edition模式安装(在该模式下无试用时长30天限制、无使用功能限制、数据库最大容量5GB),只能安装在64位的Windows 7或Windows Server 2008操作系统...
1.sybase iq配置odbc,本人亲自试验,搞了一天
sybase iq 安装,sybase iq 安装sybase iq 安装sybase iq 安装sybase iq 安装
sybase iq12.6sybase iq12.6sybase iq12.6sybase iq12.6
SYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KBSYBASE iq KB
SybaseIQ_15.1_中文用户定义函数指南.pdf
Sybase IQ AIX安装步骤,详细介绍Sybase IQ 在AIX下安装的全过程。 希望对大家有帮助。
SAP® Sybase® IQ 是面向关键任务商务智能、 分析和数据仓库而设计的高性能决策支 持服务器。 SAP Sybase IQ 中的组件集成服务提供对主机、 UNIX 或 Windows 服务器 上关系型和非关系型数据库的直接访问。
SybaseIQ系统管理指南文档! SybaseIQ系统管理指南文档! SybaseIQ系统管理指南文档! SybaseIQ系统管理指南文档!