Relationship between primary key and foreign key in MySQL

Source: Internet
Author: User
In other words, I have a forum with two tables, one with the primary thread and the other with the reply. The primary key is the only field in the table that recognizes records, it is generally the post ID, which is reflected in the access time, for example, thread. PHP? Id = 1 indicates that I want to access a post whose ID is 1 ~ Let's talk about the foreign key. When we delete a post, we need to perform another operation, that is, to delete all replies. Normally, we need to perform two delete operations (thread and reply). In this case, if a foreign key exists, for example, create a primary key (ID) pointing to the thread table in the reply table) (the Field bound to this foreign key must be the ID of the corresponding post), and specify the response to delete. When you delete the thread, mySQL will help you delete all replies from this post in the reply table, instead of manually executing the delete operation in the reply table ~ In the preceding example, the foreign key of the reply table points to the primary key of the thread table ~~
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.