Best way to store the forum thread creator?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Best way to store the forum thread creator?

Post by someberry »

I am making a small forum based system and was wondering where would be best to store the ID of the user to created the thread. At the moment, to reduce data redundancy, I am not storing the data in the thread table and only in the post table (the first post of the thread is obviously the person who made it).

However, I ran into a few problems with the SQL. Is it possible, by using joins, to get the first post ID of the thread?

Thanks :)
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Best way to store the forum thread creator?

Post by onion2k »

This is the sort of thing that a natural language key is good for ... basically store the user's name in the thread table and use it as a key to join to the users table if necessary. Most of the time you won't need to because you can just use the name as it is, saving you having to do a join at all.

The problem with this approach is that you'd have to update all the names in the threads table if a user ever changes their name...

EDIT: It was discussed in this thread - viewtopic.php?f=2&t=87385
someberry
Forum Contributor
Posts: 172
Joined: Mon Apr 11, 2005 5:16 am

Re: Best way to store the forum thread creator?

Post by someberry »

I was thinking of storing the user ID in the thread table, but I was really hoping to not have to, which is why I was wondering if I could achieve the same effect through joins.
Post Reply