a foreign key constraint fails (`zabbix`.`#sql-alter-318-2c`, CONSTRAINT `c_functions_1` FOREIGN KEY (`itemid`) REFERENCES `items` (`itemid`)) [alter table `functions` add constraint c_functions_1 foreign key (`itemid`) references `items` (`itemid`)]
SELECT COUNT(*) FROM functions WHERE itemid NOT IN (SELECT itemid FROM items);
DELETE FROM functions WHERE itemid NOT IN (SELECT itemid FROM items);

a foreign key constraint fails (`zabbix`.`#sql-alter-37a-d5`, CONSTRAINT `c_functions_2` FOREIGN KEY (`triggerid`) REFERENCES `triggers` (`triggerid`)) [alter table `functions` add constraint c_functions_2 foreign key (`triggerid`) references `triggers` (`triggerid`)]
SELECT COUNT(*) FROM functions WHERE triggerid NOT IN (SELECT triggerid FROM triggers);
DELETE FROM functions WHERE triggerid NOT IN (SELECT triggerid FROM triggers);

a foreign key constraint fails (`zabbix`.`#sql-alter-370-2b`, CONSTRAINT `c_trigger_tag_1` FOREIGN KEY (`triggerid`) REFERENCES `triggers` (`triggerid`)) [alter table `trigger_tag` add constraint c_trigger_tag_1 foreign key (`triggerid`) references `triggers` (`triggerid`)]
SELECT COUNT(*) FROM trigger_tag WHERE triggerid NOT IN (SELECT triggerid FROM triggers);
DELETE FROM trigger_tag WHERE triggerid NOT IN (SELECT triggerid FROM triggers);