資料轉移儲存過程

2022-09-01 11:30:13 字數 3098 閱讀 4740

use [db_log]

go/****** object: storedprocedure [dbo].[movefightchars] script date: 2015/5/4 16:04:59 ******/

set ansi_nulls on

goset quoted_identifier on

gocreate 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;

endend

go

HashMap轉移資料的過程

確定需要擴容之後,先計算原來陣列的長度,如果已經等於最大值了那就不可能再擴容了,直接返回。如果不是,創新乙個新的新長度的陣列。然後執行轉移方法。轉移方法 for迴圈遍歷原陣列,遍歷每乙個entry,首先儲存entry中的下乙個entry。下一次需要迴圈的 判斷是否需要重新計算hash值,如果需要就重...

資料分頁 儲存過程

if exists select from sys.objects where name pagination drop procedure pagination gocreate procedure pagination tblname nvarchar 255 表名 strgetfields n...

資料分頁 儲存過程

if exists select from sys.objects where name pagination drop procedure pagination gocreate procedure pagination tblname nvarchar 255 表名 strgetfields n...