Mysql adds multiple foreign keys/Adds Foreign keys/cascading constraints to the table

Source: Internet
Author: User

Mysql adds multiple foreign keys/Adds Foreign keys/cascading constraints to the table

1. create table 'xh' ('id' int (100) unsigned not null AUTO_INCREMENT COMMENT, 'cl _ id' smallint (3) unsigned not null comment, 'title' varchar (100) COLLATE utf8_unicode_ci not null comment, 'details' text COLLATE utf8_unicode_ci not null comment, 'date' datetime not null comment, 'au _ id' smallint (6) unsigned not null comment, 'click' int (100) unsigned not null default '0' COMMENT, 'reco' int (100) unsigned not null default '0' COMMENT, primary key ('id'), KEY 'fk _ class' ('cl _ id'), CONSTRAINT 'fk _ class' foreign key ('cl _ id ') REFERENCES 'fl '('id'), KEY 'fk _ author' ('au _ id'), CONSTRAINT 'fk _ author 'foreign key ('au _ id ') REFERENCES 'author' ('id') ENGINE = InnoDB default charset = utf8 COLLATE = utf8_unicode_ci 2. create a Foreign Key after creating the Table: Alter Table 'ym' Add constraint' fk _ author 'Foreign Key ('au _ id') References 'author' ('id'); 3. view the Table structure: Show Create Table 'ym'; 4. CASCADE: can be added at the end (can be added separately or all): on update cascade (cascade update) on delete cascade (cascade delete) for example: alter table 'ym' ADD constraint' fk _ author 'foreign key ('au _ id') REFERENCES 'author' ('id') ON UPDATE CASCADE

 


Related Article

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.