View Single Post
Old 21.05.2006, 16:48   #1
top-gear
Архивный участник
 
Join Date: Aug 2005
Posts: 605
Default [Share/Updated] Remove deleted and banned chars from the DB

As you know, all deleted chars as long as their skills/items/shortcuts etc are being kept in the database. So the db keeps growing up and lagging more. This is a simple script I just finished to remove that kind of useless data:

Code:
declare @var1 varchar(255)

Script_Start:

set @var1 = (select top 1 char_id from lin2world.dbo.user_data where account_id = '-1')

delete from lin2world.dbo.Pledge where ruler_id = @var1
delete from lin2world.dbo.Quest where char_id = @var1
delete from lin2world.dbo.shortcut_data where char_id = @var1
delete from lin2world.dbo.user_Activeskill where char_id = @var1
delete from lin2world.dbo.user_friend where char_id = @var1
delete from lin2world.dbo.user_history where char_id = @var1
delete from lin2world.dbo.user_item where char_id = @var1
delete from lin2world.dbo.user_log where char_id = @var1
delete from lin2world.dbo.user_skill where char_id = @var1
delete from lin2world.dbo.user_data where char_id = @var1

If @var1 IS NULL
            PRINT 'Finished'
ELSE
            GOTO Script_Start
EDIT:

Second script: That script will change account_id of all characters inside banned accounts to -1. Execute that script and then the first one to remove those characters completeley from the database.

Code:
declare @var1 varchar(255)

update lin2db.dbo.user_account set block_flag2 = 1  where block_flag = 1

Script_Start:

set @var1 = (select top 1 account from lin2db.dbo.user_account where block_flag2 = 1)
update lin2world.dbo.user_data set account_id = '-1'  where account_name = @var1
update lin2db.dbo.user_account set block_flag2 = 0 where account = @var1

If @var1 IS NULL
            PRINT 'Finished'
ELSE
            GOTO Script_Start

PS: the banned accounts will remain at the database but empty without chars.

I'm looking forward to finish 1 more script that will delete all banned or empty accounts.

GL
top-gear is offline