World of Warcraft - How to Remove Duplicate Gameobjects from the Database

znzz

Silver Supporter
MoP Premium
Superior Member
162
2015
28
World of Warcraft - How to Remove Duplicate Gameobjects from the Database

Simply execute the set of queries below as many times as you want and for any objects, where two or more objects use the same displayId, all duplicate objects will be deleted and all reference to those objects in the gameobjects table will be set to use the remaining gameobject.

Don't worry about objects disappearing in the game world, the query replaces all objects that use the same displayId with the object whose entry and displayId you are entering into the set of queries. This is really only useful for a highly customized server as any normal server would find a lot of the in-game objects broken or not working properly after deleting the duplicates as many of them have slightly different sets of data which may leave chairs unusable unless manually fixed, objects unusable unless manually fixed, etc...

Code:
SELECT @entry := entry, name, @display := displayId FROM gameobject_template WHERE displayId = (SELECT displayId FROM gameobject_template GROUP BY displayId ORDER BY COUNT(*) DESC LIMIT 1);
UPDATE gameobject JOIN gameobject_template ON gameobject.id = gameobject_template.entry SET gameobject.id = @entry WHERE gameobject_template.entry != @entry AND gameobject_template.displayId = @display;
DELETE FROM gameobject_template WHERE displayId = @display AND entry != @entry;

You will need to run the three queries above a few thousand times to eliminate all of the duplicate objects in the database. I simple copy-pasted the three queries over and over and over until I felt there were enough and then ran them all at once. It took a few minutes, but all of the duplicate objects were removed

Big thanks to Valkryst.
 
Top