您的位置:首页 > 数据库

每隔一段时间就从服务端下载数据使用sql语句实现

2016-04-14 19:18 501 查看
项目需求,就简单介绍一下我是怎么实现的。具体操作大家可以随时联系我<img alt="大笑" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/laugh.gif" />
主要分为两步:
一、用sql语句实现从远程数据库下载数据
二、利用windows自带的任务管理器执行你的bat脚本,其中的bat脚本是用来执行你的sql语句的
--将 服务端 192.168.121.203 主机上的 数据 每隔一段时间就下载一次。就算你的时间 在 50到65之间也是可以有办法获得的!
--因为我使用的是条件判断语句
--这是客户端代码
declare @flag int
set @flag =((select datepart(minute,getdate()))-19)
if @flag>0
begin
select * from
openrowset('SQLOLEDB', '192.168.121.203'; 'sa'; '123', test_02.dbo.stu_infor)
where
insert_minute <= (select datepart(minute,getdate()))
and
insert_minute > ((select datepart(minute,getdate()))-6)
and
insert_hour = (select datepart(hour,getdate()))
end;
else
begin
select * from
openrowset('SQLOLEDB', '192.168.121.203'; 'sa'; '123', test_02.dbo.stu_infor)
where
insert_minute<=(select datepart(minute,getdate())+60)
and
insert_minute>=((select datepart(minute,getdate())+60)-19)
union
select * from
openrowset('SQLOLEDB', '192.168.121.203'; 'sa'; '123', test_02.dbo.stu_infor)
where
insert_hour = (select datepart(hour,getdate()))
end;

二、bat文件如下:
osql -S . -d 数据库名称-U 用户名 -P 密码 -i 上面的数据库文件名.sql具体解释
三、至于windows人物管理器可以在开始菜单中找到
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: