views:

96

answers:

5

So I basically have a reviews table, and for ratings I have more than 8 factors. Because my reviews table already has 5 fields, is it better for me to just create an entire new table for ratings or add it on to the reviews table too?

Update: I should use the word criteria instead of factor. Ratings 1-5 - Humor, Readability, Customer Service, etc... Oh and some would be user inputs. For example, Who helped you? Max Powers

+1  A: 

I think you should create a separate table for it. This would make things clear for you and it won't create any overhead too.

Sarfraz
+1  A: 

There is a theory called Database normalization. You should use the third normal form one to create your database which should lead to a separate table for your ratings.

While the wikipedia article is indeed a bit confusing, this tutorial isn't.

Henrik P. Hessel
That looks so confusing.
Doug
that's correct, but you should read it when you have a moment. it provides you with the very basics of database design.
Henrik P. Hessel
I agree with Henrik's suggestion. And, if you find the tutorial confusing, rest assured that unless you take care to design your database properly it (the database) will soon become even more confusing.
High Performance Mark
+1  A: 

no need to partition the review entity into multiple tables, unless you have to support an arbitrary set of factors (in the second case it would be a 1:N relationship between reviews and factors).

if your review is always composed of 8 attributes, for example, those would be distinct properties in the same table. different factors could have different data types (service 1-10, lighting: "dark/bright", handicap-accessible: "yes/no", cuisine: "chinese") etc., so you wouldn't necessarily be able to easily move them into a sep table, because they aren't the same entity type.

jspcal
you want to call a non unique properties distinct?
Henrik P. Hessel
@Henrik: the OP said 'factors'. don't *assume* they're all the same type or belong to a sequence.
jspcal
A: 

Personally, i would have a separate table for the ratings, and i would consider going one step further - instead of having the 8 different ratings factors as columns, have them as rows instead. So your tables would look like this:

Rating Table
------------
PrimaryKey
ReviewForiegnKey
RatingTypeForiegnKey
RatingValue

RatingType Table
----------------
PrimaryKey
RatingType

That way your Rating system is expandable without changing the previously entered data - just add another RatingType in the RatingType table, and start entering rows for it in the Rating table.

slugster
So if one were to rate all 8 factors than there would be 8 rows, correct?
Doug
That is correct - you could have as few or as many ratings as you wish per Review. While you might go "wow, that could be a lot of rows", it isn't really - you are only using as much space as actual Ratings, and databases are very good at handling large amounts of rows :)
slugster
A: 

I totally agree with what Henrik said about normalization, great link!

Simply put, normalization can be summarized, as a joke, with this: "The whole key, nothing but the key, so help me Codd" (Codd is the dude that invented relational databases).

Every table has to have the "whole key" meaning it has to contain all the information about a certain entity.

It also must have "nothing but the key" so you can't store data about two different entities in one table.

In which case, whether rating should be placed in a separate table or not depends on its nature. Is it a part of ratings? Is there any good reason why you wand to put it in another table or is it just 'cause the table has "too many fields"?

Personally, I don't see any reason why it should be put in a separate table, unless you wanna follow "good practices" and put it in a separate table to meet the 3rd normal form.

Leo Jweda