Using a string column instead of an id column to differentiate records

4 views
Skip to first unread message

Mohamad El-Husseini

unread,
Feb 28, 2012, 2:09:53 PM2/28/12
to rubyonra...@googlegroups.com
How do you decide whether to use a string column or an id column to differentiate between different types of records?

Suppose you have a relationships table that maps users to forums. The possible relationships can be: subscriber, moderator, owner.

When does it make sense to move those relationship types to their own table and reference them through a relationship_type_id column? What's the criteria? Or is it better to use a string column to differentiate them?

Walter Lee Davis

unread,
Feb 28, 2012, 4:05:28 PM2/28/12
to rubyonra...@googlegroups.com

Does the client/admin want to be able to change the names or number of these groups, or are you going to be updating it (and thus could make these sorts of code-level changes) when the management winds change?

For a few options such as you have here, there's no reason to do it, IMO, since with an index, it's going to be just as fast or faster than joining another table by a numerical lookup. I would pull these options out into a constant so you only have one place to type them, too.

Walter

Reply all
Reply to author
Forward
0 new messages