数据转移存储过程

USE [Db_Log]
GO

/****** Object: StoredProcedure [dbo].[MoveFightChars] Script Date: 2015/5/4 16:04:59 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

 


CREATE PROCEDURE [dbo].[MoveFightChars]
as
begin
declare @month int
declare @Id int
set @month =1
select top 1 @Id =Id from Db_Kkxy.[dbo].FightChars where AddTime < DATEADD(mm,DATEDIFF(mm,0,dateadd(month,-@month,getdate())),0) order by AddTime

while(@Id>0)
begin
-----创建内存表
DECLARE @T table (
[ID] [bigint] NOT NULL,
[GameID] [bigint] NOT NULL,
[UserID] [int] NOT NULL,
[CharID] [bigint] NOT NULL,
[CharLevel] [int] NULL,
[CharDbID] [int] NULL,
[UsedOrder] [int] NULL,
[UsedTime] [datetime] NULL,
[UsedPill] [int] NULL,
[IsBetter] [int] NULL,
[IsWin] [int] NULL,
[IsUsed] [int] NULL,
[CurAttack] [int] NULL,
[CurPower] [int] NULL,
[CurDamage] [int] NULL,
[AddTime] [datetime] NULL
)
-----将符合条件的数据插入内存表
insert into @t(
[ID]
,[GameID]
,[UserID]
,[CharID]
,[CharLevel]
,[CharDbID]
,[UsedOrder]
,[UsedTime]
,[UsedPill]
,[IsBetter]
,[IsWin]
,[IsUsed]
,[CurAttack]
,[CurPower]
,[CurDamage]
,[AddTime]
)
select top 1000
[ID]
,[GameID]
,[UserID]
,[CharID]
,[CharLevel]
,[CharDbID]
,[UsedOrder]
,[UsedTime]
,[UsedPill]
,[IsBetter]
,[IsWin]
,[IsUsed]
,[CurAttack]
,[CurPower]
,[CurDamage]
,[AddTime] from Db_Kkxy.[dbo].FightChars where AddTime < DATEADD(mm,DATEDIFF(mm,0,dateadd(month,-@month,getdate())),0) order by AddTime

declare @tId int
-------内存表最大Id
select top 1 @tId =Id from @t order by Id desc

-------- 将内存表里面的数据插入日志表
insert into [Db_Log].[dbo].[FightChars](
[ID]
,[GameID]
,[UserID]
,[CharID]
,[CharLevel]
,[CharDbID]
,[UsedOrder]
,[UsedTime]
,[UsedPill]
,[IsBetter]
,[IsWin]
,[IsUsed]
,[CurAttack]
,[CurPower]
,[CurDamage]
,[AddTime]
)
select
[ID]
,[GameID]
,[UserID]
,[CharID]
,[CharLevel]
,[CharDbID]
,[UsedOrder]
,[UsedTime]
,[UsedPill]
,[IsBetter]
,[IsWin]
,[IsUsed]
,[CurAttack]
,[CurPower]
,[CurDamage]
,[AddTime]from @t
------删除内存表数据和原始表数据
delete @t
delete Db_Kkxy.[dbo].FightChars where Id <= @tId;

----休眠0.1秒
waitfor delay '00:00:00.100'

declare @MaxId int
set @MaxId =0

select top 1 @MaxId =Id from Db_Kkxy.[dbo].FightChars where AddTime < DATEADD(mm,DATEDIFF(mm,0,dateadd(month,-@month,getdate())),0) order by AddTime

print @tId
print @MaxId

if(@MaxId = @tId or @MaxId=0)
return;
end
end

 

 

 

GO

 

转载于:https://www.cnblogs.com/jiaqichinese/p/4476455.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值