Is there such a thing as a reverse foreign key?
问题 In MySQL, is there a way to specify that a.column cannot exist in b.column - a reverse foreign key? In other words: # Would not return any rows ever SELECT * FROM a INNER JOIN b ON a.column = b.column; # Would fail INSERT INTO a SELECT * FROM b; # Would not insert any rows INSERT IGNORE INTO a SELECT * FROM b; 回答1: No there is no such thing. You would need to do that in a trigger: DELIMITER $$ CREATE TRIGGER bi_a_each BEFORE INSERT ON a FOR EACH ROW BEGIN DECLARE forbidden_key INTEGER; SELECT