Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

[MySQL Snippet] - Find Orphaned topics / comments

edited February 2011 in Vanilla 2.0 - 2.8
A couple queries some of you that have migrated forums over might find useful. I am doing a bunch of updates against mine to fix things like old bbcode in posts, broken smiley links and decided to check for orphaned topics & comments (No user exists for the post).

Here are the queries if you are interested. These are just select statements so they won't do any harm to your data, you have to decide if you want to delete them or not.

// Orphaned topics (User not found in user table) SELECT * FROM GDN_Discussion D WHERE NOT EXISTS (SELECT NULL FROM GDN_User U WHERE D.InsertUserId = U.UserID ) ;

// Orphaned comments (User not found in user table) SELECT * FROM GDN_Comment D WHERE NOT EXISTS (SELECT NULL FROM GDN_User U WHERE D.InsertUserId = U.UserID ) ;

If you have not deleted any users you probably won't have any of these anyway.

Also ran a check for Comments with no linked Discussion (found 0!)
SELECT * FROM GDN_Comment C WHERE NOT EXISTS (SELECT NULL FROM GDN_Discussion D WHERE C.DiscussionID = D.DiscussionID);

Figured I would share in case someone else wanted to do the same.

If I get time maybe I'll whip together a plugin for this sort of thing but time is pretty rare these days... :(
Sign In or Register to comment.