Post Pacific  

Go Back   Post Pacific > Восстановленный архив > Темы без сохранившегося раздела
FAQ Community Calendar Today's Posts Search

Notices

 
 
Thread Tools Search this Thread Display Modes
Old 09.04.2007, 15:10   #1
m4rk
Архивный участник
 
Join Date: Jan 2006
Posts: 607
Default [SHARE][MSSQL QUERY] Find non existing accounts with existing chars

Abstract: I found this problem while deleting unused and banned accounts. I realized there were some (few but some after all) accounts that were deleted even if they had characters on them. So I built this query to get the ID of those accounts. Hope this saves you some time if you need this.

Check the second post by Sauron

This one will just print the account_id
Code:
--declare variables
declare @max int
declare @current int
declare @exist int

--set variables
USE LIN2WORLD
SET @max = (SELECT TOP 1 account_id from user_Data	ORDER BY account_id DESC)
SET @current = (SELECT TOP 1 account_id from user_Data WHERE account_id!= -1 ORDER BY account_id ASC)

--loop condition
WHILE @current<@max

BEGIN

USE LIN2DB
SET @exist = (SELECT COUNT(*) FROM user_account WHERE uid=@current)
IF @exist = 0 
PRINT @current

USE LIN2WORLD	
SET @current = (SELECT TOP 1 account_id from user_Data WHERE account_id>@current ORDER BY account_id ASC)

END

This one will return the SELECT * FROM user_data WHERE account_id= the non existing account in LIN2DB
Code:
--declare variables
declare @max int
declare @current int
declare @exist int

--set variables
USE LIN2WORLD
SET @max = (SELECT TOP 1 account_id from user_Data	ORDER BY account_id DESC)
SET @current = (SELECT TOP 1 account_id from user_Data WHERE account_id!= -1 ORDER BY account_id ASC)

--loop condition
WHILE @current<@max

BEGIN

USE LIN2DB
SET @exist = (SELECT COUNT(*) FROM user_account WHERE uid=@current)
IF @exist = 0 
BEGIN
USE LIN2WORLD 
SELECT * FROM lin2world.dbo.user_data WHERE account_id=@current
END

USE LIN2WORLD	
SET @current = (SELECT TOP 1 account_id from user_Data WHERE account_id>@current ORDER BY account_id ASC)

END
m4rk is offline  
Old 09.04.2007, 16:03   #2
Sauron
Архивный участник
 
Join Date: Feb 2005
Posts: 357
Default

Code:
SELECT DISTINCT(account_id) 
FROM lin2world.dbo.user_data 
WHERE account_id > 0 and account_id not in (SELECT uid FROM lin2db.dbo.user_account)
Sauron is offline  
Old 09.04.2007, 17:39   #3
m4rk
Архивный участник
 
Join Date: Jan 2006
Posts: 607
Default

Thanks Sauron, i knew there had to be an easiest way.
m4rk is offline  
Old 09.04.2007, 17:45   #4
seraphii
Архивный участник
 
Join Date: Jun 2006
Posts: 126
Default

M4rk when you delete one char from your db ,you delete only from user_data??
seraphii is offline  
Old 09.04.2007, 18:05   #5
m4rk
Архивный участник
 
Join Date: Jan 2006
Posts: 607
Default

Mmh no I delete from many other tables (i modyfied a query share by Kin).
m4rk is offline  
Old 09.04.2007, 19:41   #6
seraphii
Архивный участник
 
Join Date: Jun 2006
Posts: 126
Default

can you share... i do something like that....
seraphii is offline  
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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