How does the main table and the table get connected?

Source: Internet
Author: User
The table statement for the main table is as follows

create table topic(id int primary key not null auto_increment,title varchar(10),content varchar(20));

The data from the table is primarily used to store replies as long as there is the name and content of the reply, so how should the table be built to be associated with the main table? Ask for advice

Reply content:

The table statement for the main table is as follows

create table topic(id int primary key not null auto_increment,title varchar(10),content varchar(20));

The data from the table is primarily used to store replies as long as there is the name and content of the reply, so how should the table be built to be associated with the main table? Ask for advice

CREATE TABLE reply(    reply_id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,    replier VARCHAR,    content VARCHAR NOT NULL,    topic_id INT NOT NULL,    FOREIGN KEY (topic_id) REFERENCES topic(id) ON UPDATE CASCADE);

Just keep it correct with the foreign key.

table reply    field id auto_increment primary key,    field topic_id,    field user_id,    field content,    field datetime

Brother, have you heard of foreign keys?

  • 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.