MySQL intermediate connection deletion Problems

Source: Internet
Author: User

1. For two tables

Order table tb_order (orderid ,****)

Order and dish table tb_order_dish (orderid, dishid ,***)

 

2. Select the orderid of the Order table as the foreign key, and the orderid of the order and dish table as the subkey.

 

The SQL statement should be:

Drop table if exists 'tb _ order_dish ';
Create Table 'tb _ order_dish '(
'Orderid' int (11) not null default '0' comment 'order id ',
'Dishid 'int (11) not null default '0' comment 'dish id ',
'Dishnumber' varchar (10) default null comment' Number of dishes ',
Primary Key ('orderid', 'dishid ')
) Engine = InnoDB default charset = gb2312 comment = 'order table ';

Alter table 'tb _ order_dish'
Add constraint 'orderanddish' foreign key ('orderid') References 'tb _ order' ('orderid') on Delete cascade on update cascade;

 

 

3. You can also use a tool to create a constraint in tb_order_dish and set Partially Matching on Delete cascade.

 

4. In this way, you can delete cascade updates.

 

 

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.