In my current project, I'll be allowing users to submit ratings (TINYINT 1-5 stars) and reviews (TEXT comments) on products in the database. Users can submit ratings without reviews, but they can't submit a review without a rating. I can't decide if I should combine the reviews and ratings into a single table, or if I should keep them separate.
Here's how the tables are currently laid out:
Code:
CREATE TABLE `ratings` (
`user` INT(11) NOT NULL,
`item` INT(11) NOT NULL,
`rating` TINYINT NOT NULL,
`submit_dtm` DATETIME NOT NULL,
PRIMARY KEY (`user`, `item`)
);
CREATE TABLE `reviews` (
`user` INT(11) NOT NULL,
`item` INT(11) NOT NULL,
`review` TEXT NOT NULL,
`submit_dtm` DATETIME NOT NULL,
PRIMARY KEY (`user`, `item`)
);
Here is what I am considering changing to:
Code:
CREATE TABLE `ratings` (
`user` INT(11) NOT NULL,
`item` INT(11) NOT NULL,
`rating` TINYINT NOT NULL,
`review` TEXT,
`submit_dtm` DATETIME NOT NULL,
PRIMARY KEY (`user`, `item`)
);
I'm trying to weigh the benefits and drawbacks in combining the tables, such as:
- if combining the two tables into one, will having a nullable TEXT column be awful considering there will be many columns with a null value here?
- if leaving the two tables as they already are, how hard will it be to join the data (returning NULL for ratings or review if the primary key's value only exists in one of the two tables)?
- any other speed/space considerations I may not be aware of...
Thanks for the help, and sorry for my naivety when it comes to technical info about how a database runs and organizes data...that's my biggest fault when it comes to db design.