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