Post Pacific

Post Pacific (https://postpacific.loc-online.com/index.php)
-   Темы без сохранившегося раздела (https://postpacific.loc-online.com/forumdisplay.php?f=10001)
-   -   [share] sql. cleanup deleted chars. (https://postpacific.loc-online.com/showthread.php?t=7037)

srh 06.03.2007 08:47

[share] sql. cleanup deleted chars.
 
this code cleanup database after char get deleted.
before use any script - backup your db ;)
Code:

begin tran
delete from bookmark where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from nobless_achievements where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from olympiad_match where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from olympiad_result where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from Quest where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from shortcut_data where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from ssq_user_data where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_ActiveSkill where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_ban where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_blocklist where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_comment where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_deleted where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_friend where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_henna where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_history where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_item where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_log where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));

delete from user_macroinfo where macro_id in (SELECT macro_id FROM user_macro WHERE char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1)));
delete from user_macro where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));

delete from user_mail where id in (SELECT mail_id FROM user_mail_receiver WHERE receiver_id in (select char_id from user_data where (account_id = - 1)));
delete from user_mail where id in (SELECT mail_id FROM user_mail_sender WHERE sender_id in (select char_id from user_data where (account_id = - 1)));
delete from user_mail_receiver where receiver_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_mail_sender where sender_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));

delete from user_newbie where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_nobless where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_punish where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_recipe where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_skill where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_sociality where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_subjob where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete from user_surrender where char_id in (SELECT char_id FROM user_data WHERE (account_id = - 1));
delete FROM user_data WHERE (account_id = - 1);
commit

if someone know how to clean up pet_data this will be nice.
comments/suggestions are welcome.

if u need to delete accounts that not used in 180 days change (account_id = -1) to (login < GETDATE() - 180)

in next script we cleanup accounts that do not have any char ;)

mcrabben7 06.03.2007 09:00

Nice share. This is a pretty useful script. Good job.

Mio 06.03.2007 09:05

Nice share. Thank you.

l2serverfull 06.03.2007 09:22

nicee thxx lott

Rexx 06.03.2007 12:01

Thanks for sharing, very useful.

URANUS 06.03.2007 18:31

Good work ^_^

hr 06.03.2007 19:48

Quote:

if someone know how to clean up pet_data this will be nice.
comments/suggestions are welcome.
haven't tested, but maybe so:
1) before item deletion
Code:

delete from pet_data where pet_id in (select ui.item_id from user_item as ui left join user_data as ud on (ui.char_id=ud.char_id) where ud.account_id = - 1);
--or--

2) after item deletion
Code:

delete from pet_data where pet_id not in (select item_id from user_item);
ps: btw your item deletion is wrong. it may delete some pledges' items. this one more correct:

Code:

delete from user_item where item_id in (select ui.item_id from user_item as ui left join user_data as ud on (ui.char_id=ud.char_id) where ud.account_id = - 1 and ui.warehouse<>2);
pps: better use user_deleted table to get info about deleted chars

DR!VER 07.03.2007 04:03

Thanks, nice share ;)

srh 07.03.2007 04:54

Quote:

Originally Posted by hr (Post 80462)
pps: better use user_deleted table to get info about deleted chars

sometimes chars get deleted not from game ;)

hr 07.03.2007 07:48

if u use cached it also puts info into user_deleted

JotaC 07.03.2007 09:33

good share, i am making one to change all valors bigger than 1 in database, and i mean in punishment table, to 1, since i am having some problems with clan times.. i will post it later it may be usefull to someone too ^^

DevilsAssociate 08.03.2007 05:40

nice really usefull good job

GmZenBrasil 08.03.2007 09:19

Good job man, thanks, very good share ^^ :)

yokohiro 09.03.2007 18:08

nice really usefull good job. very good share.. thx man


All times are GMT. The time now is 15:56.