Home >Database >Mysql Tutorial >关于自身表外键触发器的实现_MySQL

关于自身表外键触发器的实现_MySQL

WBOY
WBOYOriginal
2016-06-01 13:42:271293browse

bitsCN.com 关于自身表外键触发器的实现 目前遇到这样一个外键定义:`t_girl`.`tb1`  CONSTRAINT `fk_1` FOREIGN KEY (`r_id`) REFERENCES `tb1` (`id`) ON DELETE CASCADE 目的是对于自己的另外一个字段进行约束, 其实这样看来, 后面的级联删除就没有必要了,因为针对的是同一张表的同一条记录。/* Trigger structure for table `tb1` */ DELIMITER $$ /*!50003 DROP TRIGGER*//*!50032 IF EXISTS */ /*!50003 `tr_tb1_before_insert` */$$    /*!50003 CREATE */ /*!50017 DEFINER = 'root'@'localhost' */ /*!50003 TRIGGER `tr_tb1_before_insert`          BEFORE INSERT ON `tb1`          FOR EACH ROW          BEGIN           set new.r_id = new.id;         END */$$  DELIMITER ; 我们在除了INNODB之外的其他引擎可以直接用触发器来实现。   作者 yueliangdao0608 bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn