数据库 table 为评分 table 设计并使用评分评论 table
Database table design for ratings table and review table with ratings
我有一个 table tc_res_rating
看起来像这样:
| user_id | res_id | rating | review_id | post_date (CURRENT_TIMESTAMP)|
| 1 | 13 | 4.0 | 3 | 2016-12-14 17:02:12 |
| 2 | 6 | 3.5 | NULL | 2016-12-19 20:55:24 |
和另一个 table tc_res_reviews
看起来像:
| review_id | res_id | user_id | review | date_created |
| 3 | 13 | 1 | [BLOB - 4 B] | 2016-12-14 17:02:12 |
用户可以在没有评论的情况下为餐厅创建评级,
因此评级数据将直接插入到 tc_res_rating
中 review_id
NULL。
用户还可以插入与该评论相关联的评分的餐厅评论,
所以评论被插入 tc_res_reviews
并且评级被插入 tc_res_rating
review_id
对于这种情况,这是正确的 table 模式吗?
您可以做的一件事是确保从 tc_res_reviews table.
中删除重复列(res_id 和 user_id)
我可能会完全删除 tc_res_reviews table,因为我们可以将评论本身保存在 tc_res_rating table 中。我相信一个用户只能给一家餐厅点评一次。
可以允许列评论为 NULL,以便只想给餐厅评分的用户可以保存餐厅的评分。
我有一个 table tc_res_rating
看起来像这样:
| user_id | res_id | rating | review_id | post_date (CURRENT_TIMESTAMP)|
| 1 | 13 | 4.0 | 3 | 2016-12-14 17:02:12 |
| 2 | 6 | 3.5 | NULL | 2016-12-19 20:55:24 |
和另一个 table tc_res_reviews
看起来像:
| review_id | res_id | user_id | review | date_created |
| 3 | 13 | 1 | [BLOB - 4 B] | 2016-12-14 17:02:12 |
用户可以在没有评论的情况下为餐厅创建评级,
因此评级数据将直接插入到 tc_res_rating
中 review_id
NULL。
用户还可以插入与该评论相关联的评分的餐厅评论,
所以评论被插入 tc_res_reviews
并且评级被插入 tc_res_rating
review_id
对于这种情况,这是正确的 table 模式吗?
您可以做的一件事是确保从 tc_res_reviews table.
中删除重复列(res_id 和 user_id)我可能会完全删除 tc_res_reviews table,因为我们可以将评论本身保存在 tc_res_rating table 中。我相信一个用户只能给一家餐厅点评一次。
可以允许列评论为 NULL,以便只想给餐厅评分的用户可以保存餐厅的评分。