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?