ON DELETE SET NULL
http://dev.mysql.com/doc/refman/5.1/en/innodb-foreign-key-constraints.html
[CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (index_col_name, ...)
REFERENCES tbl_name (index_col_name,...)
[ON DELETE reference_option]
[ON UPDATE reference_option]
reference_option:
RESTRICT | CASCADE | SET NULL | NO ACTION
UPDATE: If you want to do it from the perspective of A table (why on earth would you want that???), then you can't get around a trigger, e. g.
DELIMITER ;;
CREATE TRIGGER tau_A AFTER UPDATE ON A
FOR EACH ROW
BEGIN
IF OLD.b_id_1 IS NOT NULL AND NEW.b_id_1 IS NULL;
THEN
DELETE FROM B WHERE id = OLD.b_id_1;
END IF;
IF OLD.b_id_2 IS NOT NULL AND NEW.b_id_2 IS NULL;
THEN
DELETE FROM B WHERE id = OLD.b_id_2;
END IF;
END;;
Anyway, that won't set to NULL
any values in A
that have the same value, because you cannot make a trigger in MySQL, that changes the same table that triggered the trigger.
And generally, if you want weird stuff like this, I can assert with high probability that your database design is flawed. If you put more details, I could perhaps suggest a better one.
codeholic
2010-04-18 08:01:37