[Original] foreign key trigger implementation for the table itself

Source: Internet
Author: User
A foreign key definition: 't_girl '. 'tb1 'straint' fk _ 1 'FOREIGNKEY ('R _ id') REFERENCES 'tb1' ('id') ONDELETECASCADE is used to restrict another field of the user.

A foreign key definition: 't_girl '. 'tb1 'straint' fk _ 1 'FOREIGNKEY ('R _ id') REFERENCES 'tb1' ('id') ONDELETECASCADE is used to restrict another field of the user.

A foreign key definition is as follows:

'T_ gir'. 'tb1'

CONSTRAINT 'fk _ 1' foreign key ('R _ id') REFERENCES 'tb1 '('id') ON DELETE CASCADE

The purpose is to restrict another field of your own. The Hong Kong server, in fact, it seems that cascade deletion is unnecessary because it is for the same record of the same table.

/* 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;

We can use triggers for other engines except INNODB.

This article is from "god, let's see it !" Blog, Hong Kong server, please be sure to keep this source

, Virtual host

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.