Question

I have two tables, Reviews and Critic

enter image description here

I'm pretty new to RDBMS and I was wondering if the connection between Review.rID and Critic.Review is redundant?

My reasoning is that a single critic can have many reviews but each review is unique so I need a way to enforce the uniqueness of the Reviews. I did this via Review.rID which is unique. I also need to express that multiple critics can leave multiple reviews.

However, I am already connecting the critic to the review by including a criticID within Review, so is it necessary for me to also connect a reviewID to a critic within Critic?

Was it helpful?

Solution

The review column in critic means a critic can only do one review, which would make that career very unfulfilling. A primary key uniquely identifies a row, it might not necessarily enforce the uniqueness of content. In your case, the rID does not prevent the same review from being inserted multiple times.

A reviewer may have multiple reviews (including of the same movie). A review must come from one reviewer (unless you want to allow a review written by multiple critics). Based on that model, you need the FK column cID in review and nothing in critic. Additionally, the cID column should have a not null constraint because a review must belong to a critic (unless you want reviews that don't belong to any critic).

The question now is how to prevent the same review from being INSERTed multiple times. The only reliable method I can think of is to hash the review content and store the result in a column with a unique constraint in the review table.

OTHER TIPS

A foreign key can only refer to a primary or unique key of another table. The 1-M relation you drew between Critic.Review and Review.rID is impossible.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top