MySQL Forums
Forum List  »  Newbie

Re: Forum table help!
Posted by: Shawn Green
Date: May 13, 2017 02:08PM

In a relational database, each field would have just one value to it. This is so normal we call that a "normalized" schema.

Let's say that you have a table of users.

CREATE TABLE user (
user_id int
, ... other user properties ...
)

And a table of forums

CREATE TABLE forum(
forum_id int
, ... other forum properties ...
)

If each user could only ever moderate a single forum, you would put a forum_id column on the `user` table. If each forum could only ever be moderated by one user, you would put a user_id column on the `forum` table.

Now, please note... I never said you could not reuse the same forum_id value for multiple users on the `user` table (many users could moderate the same forum). All I said was that each user could only moderate 1 single forum at a time. This is an example of a one-to-many relationship (one forum, many moderators).

If you wanted a many-to-many relationship, you would need a middle table to bridge the two.

CREATE TABLE users_to_forums (
user_id int
, forum_id int
, ... other properties of the mapping ...
)

This way one user could moderate two forums (by creating two rows in this table) or the same forum could have two moderators (again, with two rows in the table).

Does that help?

Options: ReplyQuote


Subject
Written By
Posted
May 12, 2017 11:38PM
Re: Forum table help!
May 13, 2017 02:08PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.