if the database is InnoDB, you do not need to do joins when deleting. only
DELETE FROM spawnlist WHERE spawnlist.type = "monster";
can be used to delete all records associated with foreign keys in other tables; to do this, you must first link your tables at design time.
CREATE TABLE IF NOT EXIST spawnlist ( npc_templateid VARCHAR(20) NOT NULL PRIMARY KEY )ENGINE=InnoDB; CREATE TABLE IF NOT EXIST npc ( idTemplate VARCHAR(20) NOT NULL, FOREIGN KEY (idTemplate) REFERENCES spawnlist(npc_templateid) ON DELETE CASCADE )ENGINE=InnoDB;
if you use MyISAM you can delete entries like this
DELETE a,b FROM `spawnlist` a JOIN `npc` b ON a.`npc_templateid` = b.`idTemplate` WHERE a.`type` = 'monster';
in the first row, I initialized two temporary tables to delete the record, in the second row I assigned an existence table for a and b, but here I linked both tables together with the join keyword, and I matched the primary and foreign key for both tables that make the link , in the last line, I filtered the record by field for deletion.
Aylian Craspa Feb 18 '13 at 7:00 2013-02-18 07:00
source share