Ask a table structure foreign key specification

Source: Internet
Author: User
There is a scenario where a user publishes an article. Each Article corresponds to the user only. Two tables: user (id ,......) Article (id ,......) The two tables are one-to-one. Now, the question is: the id in the user is the primary key, and the auto-increment does not know how to design article better? 1: In article (id, cid), there is a scenario like this:

A user publishes an article. each article is unique to the user.

Two tables:
User (id ,......)
Article (id ,......)

The two tables are one-to-one.

Current problems:
In user, id is the primary key and auto-Increment

I don't know how to design article?

1: In article (id, cid), the id Primary Key auto-incrementing cid is the id in the user table.

2: article (id ,......) The id Primary Key auto-increment in is also the id in the user table.

3: In article (id), the id Primary Key is also the id in the user table.

4: The id in article (id) is the id in the user table. Do not use the primary key.

Do you want a unique index?

............

Now we are struggling with how to design the article table to better associate it with users?

Hope you can give me some advice and come up with the most elegant method?

Thank you!

Reply content:

There are such scenarios:

A user publishes an article. each article is unique to the user.

Two tables:
User (id ,......)
Article (id ,......)

The two tables are one-to-one.

Current problems:
In user, id is the primary key and auto-Increment

I don't know how to design article?

1: In article (id, cid), the id Primary Key auto-incrementing cid is the id in the user table.

2: article (id ,......) The id Primary Key auto-increment in is also the id in the user table.

3: In article (id), the id Primary Key is also the id in the user table.

4: The id in article (id) is the id in the user table. Do not use the primary key.

Do you want a unique index?

............

Now we are struggling with how to design the article table to better associate it with users?

Hope you can give me some advice and come up with the most elegant method?

Thank you!

Add a uid to the article table, which corresponds to the id of the user table.

I think the aid in article serves as the auto-incrementing primary key. It is good to associate the user table with the uid as a normal index.

Isn't a single table enough?

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.